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
244 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
30 /100 Needs Attention
Development Activity 12
Maintenance 0
Community 32
Maturity 48
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
67 /100 Good
Architecture 70
Code Quality 65
Innovation 78
Learning Curve 55

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 10 apps in this directory

TypeScript
99%
AGPL 3.0

Cherry Studio

AI Assistants

52,202

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

View details
89
Repo Health
84
Technical
70
Dependency
Built with
TypeScript 99%
Updated 4 days ago
TypeScript
99%
Apache 2.0

Codebuff

AI Code Assistants

12,842

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
TypeScript 99%
Updated 4 days ago
TypeScript
84%
Apache 2.0

Continue

AI Code Assistants · AI Development · Automation

36,049

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

View details
73
Repo Health
88
Technical
62
Dependency
Built with
TypeScript 84%
Updated 5 days ago
TypeScript
99%
Other

LobeHub

AI Assistants · Automation · Productivity

82,864

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
66
Dependency
Built with
TypeScript 99%
Updated 4 days ago
TypeScript
91%
MIT

OpenClaw

AI Agents · AI Assistants

390,670

An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.

View details
88
Repo Health
88
Technical
68
Dependency
Built with
TypeScript 91%
Updated 4 days ago
TypeScript
75%
MIT

OpenCode

AI Code Assistants

210,460

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
67
Dependency
Built with
TypeScript 75%
MDX 22%
Updated 4 days ago
TypeScript
96%
MIT

Pi

AI Agents

109,828

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
TypeScript 96%
Updated 5 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

39,975

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
Python 55%
TypeScript 36%
Updated 4 days ago
TypeScript
89%
MIT

Prime Agent

AI Agents · AI Code Assistants · Developer Tools

21,340

An open-source coding and research agent built around a Recursive Language Model that treats context as variables and a persistent Python REPL as its only tool.

View details
85
Repo Health
89
Technical
70
Dependency
Built with
TypeScript 89%
Updated 4 days ago

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