Live data from Hacker News

JSON River – Parse JSON incrementally as it streams in

github.com

91–100 of 101 posts

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

#91

I really like just encoding each object as JSON and then concatinating them with a new line between. Allows parsing and streaming without any special libraries and allow for an unlimited amount of data (with objects being reasonably sized). Usually gives these files the .jsonlines suffix when stored on disk. Allows for batch process without requiring huge amounts of memory.

Based on this thread that's called NDJSON Newline Delimited JSON TIL

It's also known as JSONL (JSON Lines).

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

#92

I really like just encoding each object as JSON and then concatinating them with a new line between. Allows parsing and streaming without any special libraries and allow for an unlimited amount of data (with objects being reasonably sized). Usually gives these files the .jsonlines suffix when stored on disk. Allows for batch process without requiring huge amounts of memory.

[deleted]

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

#94
post #91

Earlier quoted context omitted.

Based on this thread that's called NDJSON Newline Delimited JSON TIL

It's also known as JSONL (JSON Lines).

I'm pretty sure jsonl was a bit earlier as a term, but ndjson is now the more prominent term used for this... been using this approach for years though, when I first started using Mongo/Elastic for denormalized data, I'd also backup that same data to S3 as .jsonl.gz Leaps and bounds better than XMl at least.

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

#95
post #84
post #64

Earlier quoted context omitted.

Seems useful to me in the context of something like a progressively rendered UI. A large block of text appearing a few characters at a time would be fine, but a number that represents something like a display metric (say, a position, or font-size) going from 0 to 0.5 or from 1 to 1000, would result in goofy gyrations on-screen that don't make any sense. Or imagine if it was just fields in the app's data. Name: John S…

If you're updating the UI every time you receive a single character from this library, you've got bigger problems than font size.

If your UI layer can't efficiently update when you get new characters, you've got bigger problems than JSON parsing.

Seriously, you should be able to update the UI with a new character, and much more, at 60fps easily.

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

#96
post #86
post #71

Earlier quoted context omitted.

Only for numbers! Strings, objects, arrays, true, false, and null all have an unambiguous ending.

but you don't do this for strings either, as shown in the examples - partial strings are pushed even though they're not yet ended: {"name": "Ale"}

Oh this isn't about the public API, it's about the internal logic of the parser.

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

#97
post #77
post #72

Earlier quoted context omitted.

I want to ditch stream-json so hard (needs polyfills in browser, cumbersome to use), but I need only one feature: invoke callback by path (e.g. `user.posts` need to invoke for each post in array) only for complete objects. Is this something that json river can support?

jsonriver's invariants do give you enough info to notice which values are and aren't complete. They also mean that you can mutate the objects and arrays it returns to drop data that you don't care about. There might be room for some helper functions in something like a 'jsonriver/helpers.js' module. I'll poke around at it.

Please consider it a feature request

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

#99
post #84
post #64

Earlier quoted context omitted.

Seems useful to me in the context of something like a progressively rendered UI. A large block of text appearing a few characters at a time would be fine, but a number that represents something like a display metric (say, a position, or font-size) going from 0 to 0.5 or from 1 to 1000, would result in goofy gyrations on-screen that don't make any sense. Or imagine if it was just fields in the app's data. Name: John S…

If you're updating the UI every time you receive a single character from this library, you've got bigger problems than font size.

Isn't that one of the main points of React and its ilk? The state is just a big JSON object, and sometimes you might be fetching a bunch of data that makes up that state, and streaming it in. If latency is high and volume of data is high, seems perfectly reasonable to get the UI rendering as the state comes in instead of waiting for the last byte to do anything.

For instance, imagine you don't fully control the backend to split up a large response into several smaller API calls, but you could render the top part of the UI, which may be the most useful part, from the first couple of keys in the JSON, while a large "transaction history" after that is still downloading.

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

#100

I really like just encoding each object as JSON and then concatinating them with a new line between. Allows parsing and streaming without any special libraries and allow for an unlimited amount of data (with objects being reasonably sized). Usually gives these files the .jsonlines suffix when stored on disk. Allows for batch process without requiring huge amounts of memory.

jq allows to covert normal json document to jsonlines and back, though it does it much faster if it can slurp an original doc into memory (no --stream option)
Post reply on HN