Pretty print JSON python

后端 未结 1 534
野趣味
野趣味 2020-12-14 03:45

if anybody with some knowledge about pretty printing JSON could help me with this I would be extremely grateful!

I\'m looking to convert a complex python string into

相关标签:
1条回答
  • 2020-12-14 04:16

    You are writing Python representations, not JSON.

    Use the json.dump() function to write pretty-printed JSON instead, directly to your file:

    with open('data.txt', 'wt') as out:
        res = json.dump(obj, out, sort_keys=True, indent=4, separators=(',', ': '))
    
    0 讨论(0)
提交回复
热议问题