JSON dumps format Python

There’s a parameter called indent. It is None by default, which means “no pretty printing”. If you set it to an integer value, it will enable pretty-printing, and use that many spaces to indent nested elements.

In your case it will be something along the lines of:

json.dumps(links, outfile, indent=4)

(or indent=2 if you prefer less spaces). Here’s an example from the docs (link), which shows more functionality you might also want as you progress:

>>> import json
>>> print json.dumps({'4': 5, '6': 7}, sort_keys=True,
...                  indent=4, separators=(',', ': '))
{
    "4": 5,
    "6": 7
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)