Parse JSON into ordered data-structure (in python)

来源:互联网 发布:乖戾知乎 编辑:程序博客网 时间:2024/06/05 22:31

From 点击打开链接

In many cases it is essential (or at the least nicer) to preserve key order from a parsed JSON document, here is how to do it in python (using the std lib json module and OrderedDict available in python 2.7+)

from collections import OrderedDictimport jsonr = json.load(open('file.json'), object_pairs_hook=OrderedDict)print json.dumps(r, indent=2)
0 0
原创粉丝点击