Description
partial-json is a small JavaScript library for parsing partial JSON strings, such as the output of a language model that is still streaming. A normal JSON.parse call fails on text that is cut off partway through, but partial-json can return as much of the data as it can, so you can show results while the response is still arriving. It works like JSON.parse for complete strings. For partial strings, you pass a second parameter built from the Allow object, a set of bitwise flags that decides which types may be incomplete. Types not included in allow only appear once they are complete. For example, allowing partial strings lets a key appear with a partly written value, while without it the key is left out until its string closes. Partial arrays and special values can also be allowed. The default setting is to allow everything. The library is pure JavaScript and ships both CommonJS and ES module builds, and the README links to a demo and a Python implementation. The source is public on GitHub under the promplate organization. It suits developers who stream structured output from LLMs to users in real time.…
Highlights
- Parses incomplete JSON from streams
- Works like JSON.parse for complete input
- Allow flags for partial strings, objects and arrays
- CommonJS and ES module builds
Ratings & Reviews
No ratings yet
Be the first to rate Partial Json Parser JS.
People also visit
Openai Partial Stream
Turn a stream of token into a parsable JSON object as soon as possible
Partial Json Parser JS FAQ
What does partial-json do?
It parses a JSON string that has been cut off, such as a streamed model response, and returns the data that is complete so far.
How do I install it?
The library is available as a CommonJS and ES module build, and the README shows the install steps and import examples.
How do I allow partial values?
Pass a second parameter to parse made from the Allow flags, combined with bitwise OR. For example, Allow.STR lets a string be incomplete.
Is there a Python version?
Yes. The README mentions a Python implementation.
What are the best Partial Json Parser JS alternatives?
Popular alternatives to Partial Json Parser JS include Openai Partial Stream, Partial Json Parser and Json Repair. See all Partial Json Parser JS alternatives

.png?auto=compress&fit=max&w=128)




