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
This is somewhat related to #5. Although it is probably safe to assume that the JSON dictionary I'm trying to parse will always be in the same order... it might not.
Therefore, I'd like to do something like:
hourly_file=io.open("hourly.json",'rb')
json_data=adafruit_json_stream.load(hourly_file)
periods=json_data['properties']['periods']
forperiodinperiods:
for (key,value) inperiod.items():
print(f"{key} = {value}")
But, there is no items() in TransientObject. How hard would this be to implement? (The above code works with full json_stream, as does something like:
I tried briefly to implement this, but ran into problems (not surprisingly) nested dictionaries -- _IterToStream.next_value() returns those as transient objects, which presents a conundrum. If the iterator skips past that, that item can never be read. But if it doesn't, things are kind of in a weird state. (I think this is what the active_child value is for?)
I think maybe the solution is to "realize" any nested dictionaries or lists. That is, if the buffer expected to be a value starts with { or [ , buffer everything until the matching } or ] (including any further nested dictionaries or lists, so it might not necessarily be the next end-char encountered!) and then json.loads() that buffer and return the result as value. And then, document this as an implementation detail, warning people not to iterate over dictionaries with large nested objects unless there's plenty of memory.
Anyway, this turned into a longer lunch break than I intended :) so I am going to stop the yak-shaving here.
This is somewhat related to #5. Although it is probably safe to assume that the JSON dictionary I'm trying to parse will always be in the same order... it might not.
Therefore, I'd like to do something like:
But, there is no
items()
in TransientObject. How hard would this be to implement? (The above code works with fulljson_stream
, as does something like:which is basically exacatly what I want to do (except more than just printing of course).
The text was updated successfully, but these errors were encountered: