How to Change Default Separator in Python


In this example we will show how to change the default separator using the separators parameter in the json.dumps() method in Python.

Source Code

import json

my_dict = {
    'name': 'Jim',
    'age': 14,
    'id': '15'
}

python_to_json_1 = json.dumps(my_dict)
print(python_to_json_1)

python_to_json_2 = json.dumps(my_dict, indent=4, separators=('.', '='))
print(python_to_json_2)

Output:

{"name": "Jim", "age": 14, "id": "15"}
{
    "name"="Jim".
    "age"=14.
    "id"="15"
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments