How to beautify JSON in Python?

后端 未结 13 1598
渐次进展
渐次进展 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:50

    You could pipe the output to jq. If you python script contains something like

    print json.dumps(data)
    

    then you can fire:

    python foo.py | jq '.'
    

提交回复
热议问题