-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Description
Using higher level interfaces, is there a way to iterate over more than one prefix?
Detailed description
First of all, thank you very much for this great library!
I am using ijson to transform a long JSON response from a graphQL server into python objects. Unfortunately, if the server encounters an error, the response status code is still 200 with the response body containing some JSON error message. So, the response can be in one of two formats:
# good response
{"data": [...]}
# bad response
{"errors": [...]}
-
Is there a way to transform the data for a good response and raise an error in case there is a bad response?
-
I know I can achieve the desired behaviour using the low-level
parse
function. The issues I have with this approach is that- It feels like I have to reverse-engineer the higher level interface. Since I would like to process dicts, just like the high-level interfaces provide, iterating the
parse
results would need to build dictionaries out of token events - I am concerned that I loose the performance benefit from running C instead of python code
How bad would you say is the performance loss when building dictionaries from token events compared to the C implementation? Is it even worth using ijson in this case?
- It feels like I have to reverse-engineer the higher level interface. Since I would like to process dicts, just like the high-level interfaces provide, iterating the
-
If not already requested, I would like to follow up this question with a feature request that enhances the high-level interfaces to something like:
for prefix, item in ijson.items(f, {'earth.europe.item', 'earth.america.item'}):
if prefix == 'earth.europe.item':
do_something_with_european_country(item)
elif prefix == 'earth.america.item':
raise ValueError(f"Did not expect American country: {item}")
Why is this not clear from the documentation
The use case is not mentioned