Partial JSON

Parses incomplete JSON strings streamed token-by-token from an LLM into usable JavaScript values as they arrive.

Library
npm
v0.1.7
244stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
31/100Needs Attention
Development Activity16
Maintenance0
Community32
Maturity48
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
67/100Good
Architecture70
Code Quality65
Innovation78
Learning Curve55

Partial JSON solves a problem specific to streaming LLM output: a model’s structured response arrives one token at a time, so at any point before the final token the JSON is syntactically broken and JSON.parse throws. Partial JSON walks the string with a single recursive-descent pass and returns the best value it can reconstruct from what has streamed so far, so a UI can render an object’s fields as they complete instead of waiting for the whole payload.

Rather than an all-or-nothing “partial mode”, it exposes a bitmask (Allow.STR, Allow.NUM, Allow.ARR, Allow.OBJ, Allow.NULL, Allow.BOOL, Allow.NAN, Allow.INFINITY, Allow._INFINITY) so callers decide exactly which value types are allowed to be incomplete — for example allowing partial strings and objects but requiring numbers to be fully written before they appear. It throws a distinct PartialJSON error when the string is simply unfinished (recoverable, keep streaming) versus MalformedJSON when it’s genuinely invalid, so callers can branch on the two cases instead of treating every parse failure the same way. The library is dependency-free, ships both CommonJS and ESM builds, and is published to both npm and JSR.

What You Get

  • A parse() function that behaves exactly like JSON.parse on complete input, and gracefully degrades on incomplete input
  • Fine-grained Allow bitmask flags to control which value types (strings, numbers, arrays, objects, null/bool, NaN/Infinity) are permitted to be partial
  • Distinct PartialJSON and MalformedJSON error classes so callers can tell “still streaming” apart from “actually broken”
  • Dual CommonJS/ESM builds with bundled TypeScript type declarations, published to both npm and JSR
  • A companion Python implementation (partial-json-parser on PyPI) for teams working across both stacks

Common Use Cases

  • Rendering a structured LLM response (e.g. a tool call or JSON-mode completion) into the UI as it streams, instead of waiting for the full payload
  • Building chat UIs that progressively reveal fields of a streamed JSON object as the model finishes each key
  • Validating and recovering usable data from truncated or cut-off JSON logs and API responses
  • Powering custom streaming parsers layered on top of OpenAI/Anthropic-style token streams

Under The Hood

Architecture The library is a single recursive-descent parser (src/index.ts) built around a closure-based cursor (index/length) that walks the input string once, dispatching on the current character to parseStr/parseObj/parseArr/parseNum/literal matchers; partiality is handled locally in each sub-parser by catching an unexpected end-of-input and, if the corresponding Allow bit is set, returning what was built so far instead of propagating the error. Configuration is isolated into its own module (src/options.ts) as plain bitwise constants composed into higher-level groups (ATOM, COLLECTION, ALL), keeping the parsing logic and the partiality policy cleanly separated despite the whole implementation living in two files.

Tech Stack Written in strict-mode TypeScript targeting ESNext, compiled with tsc to a dist/ output that ships both CommonJS and ESM entry points plus .d.ts declarations. Zero runtime dependencies. Tests run on Vitest with Istanbul coverage; CI (GitHub Actions) builds with Bun, runs the coverage suite, publishes a coverage report to GitHub Pages, and separately publishes the built package to both the npm registry and JSR on tagged releases.

Code Quality A Vitest suite (tests/examples.test.js) exercises the parser against string, array, object, singleton (null/true/false), and numeric edge cases for each Allow flag combination, including several negative cases that assert a specific error type is thrown. Strict TypeScript catches type misuse at compile time, and Prettier enforces consistent formatting, though there is no separate linter (ESLint) configured and the test suite covers behavior rather than exhaustive input fuzzing.

API Design The single-function surface (parse, plus the Allow bitmask and two error classes) mirrors the built-in JSON.parse signature closely enough that adopting it is a near drop-in swap, while the bitmask lets a caller be as permissive or as strict as their use case needs without any additional configuration objects. Naming (Allow.STR, Allow.OBJ, etc.) and the recoverable-vs-fatal error split are documented directly in the source via JSDoc comments that also populate the published type declarations.

Used by 7 apps in this directory

TypeScript
99%
AGPL 3.0

Cherry Studio

AI Assistants

51,521

All-in-one AI desktop client with 300+ assistants and multi-model support

View details
89
Repo Health
84
Technical
71
Dependency
Built with
TypeScript99%
Updated today
TypeScript
98%
Apache 2.0

Codebuff

AI Code Assistants

11,750

An open-source AI coding assistant that coordinates specialized agents to edit your codebase from natural language — including Freebuff, a free, ad-supported version powered entirely by open-source models like DeepSeek and Kimi.

View details
85
Repo Health
71
Technical
67
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,808

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
81
Repo Health
88
Technical
62
Dependency
Built with
TypeScript84%
Updated yesterday
TypeScript
99%
Other

LobeHub

AI Assistants · Productivity · Automation

82,273

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
69
Dependency
Built with
TypeScript99%
Updated today
TypeScript
75%
MIT

OpenCode

AI Code Assistants

205,271

A fully open-source AI coding agent built for the terminal, with a TUI, desktop app, web client, plugin system, and SDK — one of the most-starred AI coding agents on GitHub.

View details
89
Repo Health
76
Technical
66
Dependency
Built with
TypeScript75%
MDX21%
Updated today
TypeScript
95%
MIT

Pi

AI Agents

102,409

An open-source, self-extensible agent harness and coding agent CLI — a modular runtime (agent core, unified multi-provider LLM API, TUI) with no built-in permission system by default, documented containerization patterns for sandboxing instead.

View details
88
Repo Health
73
Technical
74
Dependency
Built with
TypeScript95%
Updated yesterday
Python
54%
Other

PostHog

Analytics · Monitoring · Developer Tools

39,612

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python54%
TypeScript36%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search