How to beautify JSON in Python?

后端 未结 13 1367
渐次进展
渐次进展 2021-01-29 18:55

Can someone suggest how I can beautify JSON in Python or through the command line?

The only online based JSON beautifier which could do it was: http://jsonviewer.stack.h

13条回答
  •  迷失自我
    2021-01-29 19:41

    Use the indent argument of the dumps function in the json module.

    From the docs:

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

提交回复
热议问题