Skip to content
Discussion options

You must be logged in to vote

@adriansev assuming you want to loop through the individual objects inside the top-level array you'd want to do:

# f is your file/socket/etc.... that is already opened
for element in ijson.items(f, "item"):
    # do something with element

The "Prefix" section in the documentation explains how the prefix works.

On the command line you can also inspect what the prefix looks at different parts of the parsing process, which can help you determine what prefix you want to use:

$> echo '[{"a": 1}, {"a": 2}]' | python -mijson.dump -m parse
#: path, name, value
--------------------
0: , start_array, None
1: item, start_map, None
2: item, map_key, a
3: item.a, number, 1
4: item, end_map, None
5: it…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@adriansev
Comment options

Answer selected by rtobar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants