3 ms·
If you've got some client side code and want to parse and render JSON progressively, try out jsonriver: https://github.com/rictic/jsonriver https://github.com/r
by rictic 1y ago
If you've got some client side code and want to parse and render JSON progressively, try out jsonriver: https://github.com/rictic/jsonriver https://github.com/rictic/jsonriver
Very simple API, takes a stream of string chunks and returns a stream of increasingly complete values. Helpful for parsing large JSON, and JSON being emitted by LLMs.
Extensively tested and performance optimized. Guaranteed that the final value emitted is identical to passing the entire string through JSON.parse.
- jumploops 1y agoWhat’s the benefit of `jsonriver` over one of the myriad of “best effort” parsers[0][1][2] in a try/catch loop while streaming? [0]https://github.com/beenotung/best-effort-json-parser https://github.com/beenotung/best-effort-json-parser [1]https://github.com/unjs/destr https://github.com/unjs/destr [2]https://www.npmjs.com/package/json-parse-even-better-errors https://www.npmjs.com/package/json-parse-even-better-errors
- rictic 1y agoGood question. jsonriver is well optimized, exhaustively tested (tens of thousands of test cases), and provides a number of potentially useful invariants[0] about its parsing. jsonriver's performance comes primarily from simplicity, and doing as little work per character as we can. Repeatedly reparsing from scratch on the other hand gets expensive quick, your parse time is quadratic in the length of the string to parse. [0] https://github.com/rictic/jsonriver?tab=readme-ov-file#invariants https://github.com/rictic/jsonriver?tab=readme-ov-file#invar...
- jumploops 1y agoI've been looking for a better solution for awhile now (if you couldn't tell), and will definitely try out jsonriver for our use-case. Thanks!