In this example we will show how to define the numbers of indents using the indent 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)
print(python_to_json_2)
Output:
{"name": "Jim", "age": 14, "id": "15"}
{
"name": "Jim",
"age": 14,
"id": "15"
}