isagalaev / ijson

Iterative JSON parser with Pythonic interface
http://pypi.python.org/pypi/ijson/
Other
615 stars 134 forks source link

Get root items only #18

Closed johngouf closed 10 years ago

johngouf commented 10 years ago

Hi there,

imagine that I have a big array of json objects without an identifier. For instance: [ { "id":"sdfsdf", "service_name":"sdfsfd", "expiration":"2099-12-31T00:00:00Z", "brief_description":"sdfsdfsdfsdfsdf" }, { "id":"fsdfsdfsdf", "service_name":"sdfsdf", "expiration":"2099-12-31T00:00:00Z", "brief_description":"sdfsdfdsf." }, .. ... ... ... ]

how is it possible to use items function? (since there is no key for each json object) Thanks a lot

isagalaev commented 10 years ago

Array items are fetched with the keyword "item", so for the top-level array it's ijson.items(f, 'item'). And ijson.items(f, '') will give you the whole array as a single object.

johngouf commented 10 years ago

Thanks so much for the immediate response. It is of course working.