You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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:
forprefix, iteminijson.items(f, {'earth.europe.item', 'earth.america.item'}):
ifprefix=='earth.europe.item':
do_something_with_european_country(item)
elifprefix=='earth.america.item':
raiseValueError(f"Did not expect American country: {item}")
Why is this not clear from the documentation
The use case is not mentioned
The text was updated successfully, but these errors were encountered:
@hotaru355 I'm currently just messaging to acknowledge that I've seen this message and I'm aware of it. I'm however unable to properly reply for a couple of weeks, so don't expect any action on this immediately. Thanks!
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:
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 thatparse
results would need to build dictionaries out of token eventsHow 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?
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:
Why is this not clear from the documentation
The use case is not mentioned
The text was updated successfully, but these errors were encountered: