+2 votes
in Programming Languages by (11.5k points)
How can I print json data with some indentation?

e.g.

{"Name": "ABC", "ID": 123}

as

{

    "Name": "ABC",

    "ID": 123

}

1 Answer

0 votes
by (20k points)

For the pretty printing of JSON data, you can use parameter "indent" with function dumps(). Here is an example:

>>> import json
>>> a = {'Name': 'ABC', 'ID': 123}
>>> v = json.dumps(a, indent=4)
>>> print(v)
{
    "Name": "ABC",
    "ID": 123
}
...