json_dumps
Serializes a native object (dictionary, list, string, number, etc.) into a JSON-formatted string. This is useful when you need to convert structured data into a JSON string for storage or transmission.
Syntax
json_dumps(obj)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| obj | any | Yes | The native object to serialize into JSON. Can be a dictionary, list, string, number, boolean, or null. |
Returns
Type: string
A JSON-formatted string representing the input object.
Examples
Serialize a dictionary:
json_dumps([record_data])
If record_data is {"key": "value", "count": 5}, the result is '{"key": "value", "count": 5}'.
Serialize a list:
json_dumps([tags])
If tags is ["network", "urgent"], the result is '["network", "urgent"]'.
Build and serialize a custom object:
json_dumps({"source": [sys_id], "migrated": true})
If sys_id is "abc123", the result is '{"source": "abc123", "migrated": true}'.
Notes
- This is the inverse of
json_loads. - The output uses compact formatting by default (no extra whitespace).
- Additional keyword arguments can be passed to control serialization behavior (e.g., indentation), following Python's
json.dumpsconventions.
Comments
0 comments
Please sign in to leave a comment.