Live data from Hacker News

JSON River – Parse JSON incrementally as it streams in

github.com

1–10 of 101 posts

Re: JSON River – Parse JSON incrementally as it streams in

#2
I wrote a more traditional JSON parser for my microcontooller project. You could iterate over elements and it would return "needs more data" if it was unable to proceed. You could then call it again after fetching more. Then just simple state machines to consume the objects.

The benefit with that was that you didn't need the memory to store the deserialized JSON object in memory.

This seems to be more oriented towards interactivity, which is an interesting use-case I hadn't thought about.

Re: JSON River – Parse JSON incrementally as it streams in

#3

I wrote a more traditional JSON parser for my microcontooller project. You could iterate over elements and it would return "needs more data" if it was unable to proceed. You could then call it again after fetching more. Then just simple state machines to consume the objects. The benefit with that was that you didn't need the memory to store the deserialized JSON object in memory. This seems to be more oriented toward…

I found this because I am interested in streaming responses that populate a user interface quickly, or use spinners if it is loading still

Re: JSON River – Parse JSON incrementally as it streams in

#5
post #4

Interesting approach. I would expect an object JSON stream to be more like a SAX parser though. It's familiar, fast and simple. Any thougts on not chosing the SAX approach?

I think this is a lot like etree in python's streaming approach for XML, but with a simpler API, and incremental text parsing. With etree in python, you can access the incomplete tree data and not have to worry about events. So it's missing the SAX API part of a SAX approach, but is built like some real world libraries that use the SAX approach, which end up having a hybrid of events and trees.

Re: JSON River – Parse JSON incrementally as it streams in

#8
post #6

I can't imagine a usecase. Ok, you receive incremental updates, which could be useful, but how to find out that json object is actually received in full already?

When its closing brace or square bracket appears.

EDIT: this is totally wrong and the question is right.

Re: JSON River – Parse JSON incrementally as it streams in

#9
post #6

I can't imagine a usecase. Ok, you receive incremental updates, which could be useful, but how to find out that json object is actually received in full already?

When its closing brace or square bracket appears. EDIT: this is totally wrong and the question is right.

[deleted]

Re: JSON River – Parse JSON incrementally as it streams in

#10
Maybe I'm wrong but it seems like you would only want to parse partial values for objects and arrays, but not strings or numbers. Objects and arrays can be unbounded so it makes sense to process what you can, when you can, whereas a string or number usually is not.
Post reply on HN