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
JSON River – Parse JSON incrementally as it streams in
91–100 of 101 posts
Re: JSON River – Parse JSON incrementally as it streams in
#92I 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.
Re: JSON River – Parse JSON incrementally as it streams in
#93Re: JSON River – Parse JSON incrementally as it streams in
#94Earlier quoted context omitted.
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
#95Earlier 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.
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
#96Earlier 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"}
Re: JSON River – Parse JSON incrementally as it streams in
#97Earlier 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.
Re: JSON River – Parse JSON incrementally as it streams in
#98Install with `uv install jsonriver`
Re: JSON River – Parse JSON incrementally as it streams in
#99Earlier 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.
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
#100I 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.