Google News
logo
Use the indent parameter to define the numbers of indents
The Following example of Use the indent parameter to define the numbers of indents :
Program :
import json

data = {
    "name": "John",
    "age": 30,
    "city": "New York"
}

json_string = json.dumps(data, indent=4)
print(json_string)
Output :
{
    "name": "John",
    "age": 30,
    "city": "New York"
}
In this example, the `json.dumps()` function is used to convert the `data` dictionary into a JSON string.

The `indent` parameter is set to 4 to add 4 spaces for each level of indentation.