Read top-level JSON dictionary incrementally using Python ijson
问题 I have the following data in my JSON file: { "first": { "name": "James", "age": 30 }, "second": { "name": "Max", "age": 30 }, "third": { "name": "Norah", "age": 30 }, "fourth": { "name": "Sam", "age": 30 } } I want to print the top-level key and object as follows: import json import ijson fname = "data.json" with open(fname) as f: raw_data = f.read() data = json.loads(raw_data) for k in data.keys(): print k, data[k] OUTPUT: second {u'age': 30, u'name': u'Max'} fourth {u'age': 30, u'name': u