Skip to content
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

Working without prefixes? #46

Closed
Themanwithoutaplan opened this issue Apr 9, 2021 · 2 comments
Closed

Working without prefixes? #46

Themanwithoutaplan opened this issue Apr 9, 2021 · 2 comments
Labels
question Further information is requested

Comments

@Themanwithoutaplan
Copy link

I may have misunderstood the library, but is there any way to loop over structures without any prefixes? I've been working in a memory-constrained environment where I wish to replace something like the following

data = json.load(srcfile)
for value in data.values():
       do_something(value)

ie. converting some JSON into CSV.

To do this with IJSON I've had to drop down to the basic_parser() where I manually handle start_array and end_array, concatenate values and ignore other events. But it feels like there should be another way.

@rtobar
Copy link

rtobar commented Apr 10, 2021

@Themanwithoutaplan based on what you describe and on your code (you use data.values() so I'm assuming your JSON document has a dictionary at the top level) I think you want to use the kvitems function with an empty prefix (i.e., ''), and look at the resulting values.

If instead your JSON document has an array at the top level you'll want to use the items function with an item prefix.

@rtobar rtobar added the question Further information is requested label Apr 10, 2021
@Themanwithoutaplan
Copy link
Author

Thanks very much! I thought that might be the case because the docs do mention the empty string. I might make a PR to the docs to make this option a bit clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants