-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ijson.kvitems(prefix) iterates through items even after the prefix was found and closed #61
Comments
@nisace thanks for the very thorough report. I think there's a misalignment between the expectations you have for your particular JSON document and prefix, and how $> echo '[{"b": 1}, {"b": 1}]' | python -m ijson.dump -m kvitems -p item
#: key, value
-------------
0: b, 1
1: b, 1 $> echo '{"a": {"b": 1}, "a": {"b": 1}}' | python -m ijson.dump -m kvitems -p a
#: key, value
-------------
0: b, 1
1: b, 1 The first case is not uncommon, and the second is a bit weirder, in the sense that the input JSON document has duplicate keys -- but possible, as the JSON specification doesn't disallow duplicate keys. These two examples should hopefully make it clear that However.... I do see the opportunity to implement a new option for Thoughts? |
@rtobar thanks for your answer. Indeed, I understand your point and agree with the Not sure how to implement though :) |
Yeah, I have some ideas but it could take a while. I'll close this ticket and create a new one to keep track of the potential new feature. |
Describe the bug
ijson.kvitems(prefix)
iterates through items even after the prefix was found and closed.How to reproduce
If first generated an
example.json
file with the following code.This gives the following JSON for
n=5
Then I tried to load only the items under the prefix
a
with the two following functions:To compare the two functions, I created a big
example.json
file withn=10000000
.The function
h
took 0.43s to execute while the functiong
took 2.60s. Thus it seems thatijson.kvitems(prefix)
iterates through items even after the prefix was found and closed (i.e eventend_map
is found).Expected behavior
ijson.kvitems(prefix)
should stop iterating through items once the prefix was found and closed.Execution information:
Thanks !
The text was updated successfully, but these errors were encountered: