jsonc-parser

A fault-tolerant scanner and parser for JSONC (JSON with comments), with SAX-style visiting, DOM trees, and edit APIs.

Library
npm
v3.3.1
753stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
63/100Good
Development Activity64
Maintenance36
Community64
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture85
Code Quality82
Innovation76
Learning Curve78

jsonc-parser is Microsoft’s scanner and parser for JSONC — JSON extended with JavaScript-style comments and trailing commas — originally built to power JSON language support in VS Code. It exposes a low-level tokenizing scanner, a fault-tolerant parse() function that still returns a best-effort result on invalid input (while reporting errors separately), a SAX-style visit() callback API, and a parseTree() function that builds a hierarchical DOM with source offsets for every node.

Beyond parsing, the package includes format() and modify() APIs that compute textual edit operations for reformatting a document or inserting/removing/replacing a property or array item, plus applyEdits() to apply them — enabling tools to make targeted, whitespace-preserving edits to a JSON/JSONC file rather than re-serializing the whole document.

What You Get

  • A low-level createScanner() tokenizer that yields tokens with offsets, line, and column information
  • A fault-tolerant parse() function that returns a best-effort JS value plus a separate list of errors
  • A SAX-style visit() API with callbacks for object/array boundaries, properties, literals, and comments
  • parseTree() to build a hierarchical DOM (Node tree) with offsets, plus findNodeAtLocation/findNodeAtOffset/getLocation helpers to navigate it
  • format() and modify() APIs that compute textual edit operations instead of requiring full re-serialization
  • stripComments() utility to convert JSONC to plain JSON

Common Use Cases

  • Parsing configuration files (tsconfig.json, VS Code settings/tasks/launch configs) that allow comments
  • Building editor tooling — syntax highlighting, outline views, or diagnostics — over JSON/JSONC documents using the scanner or visitor APIs
  • Programmatically inserting or updating a single property in a JSON config file while preserving existing formatting and comments
  • Implementing IntelliSense or path-based navigation over JSON documents via getLocation/findNodeAtLocation

Under The Hood

Architecture — the package is layered around src/impl/scanner.ts (a character-level tokenizer emitting SyntaxKind tokens with offsets/line/column), src/impl/parser.ts (which drives the scanner to implement both the SAX-style visit() callbacks and the higher-level parse()/parseTree() entry points), src/impl/edit.ts (computes textual edit operations for modify()), and src/impl/format.ts (computes formatting edits); main.ts re-exports the public surface. Because parseTree()/parse() are both built on the same underlying scanner/parser pass, offset and line/column information stays consistent whether consumers want a full DOM or a lightweight streaming visit. Tech Stack — pure TypeScript compiled to an ESM-only package (type: module, single exports entry pointing at compiled lib/esm), with zero runtime dependencies; built with tsc, linted with the flat-config ESLint + @typescript-eslint, tested via Node’s built-in --test runner rather than a separate test framework. Code Qualitysrc/test/ has dedicated suites for JSON parsing (json.test.ts), editing (edit.test.ts), formatting (format.test.ts), and the string-interning optimization (string-intern.test.ts); the prepack script enforces compile+test+lint before any publish, and a string-intern.ts module exists specifically to reduce allocation overhead for repeated property-name strings during parsing of large documents. API Design — the API separates concerns cleanly (scan vs. visit vs. parse vs. parseTree vs. edit) so consumers only pull in as much machinery as they need; fault tolerance is explicit rather than implicit — parse() takes an optional errors output array so callers must consciously choose to inspect parse errors, and JSDoc comments on every exported function/interface make the library usable directly from editor tooltips without external docs.

Used by 22 apps in this directory

TypeScript
88%
Other

AFFiNE

Productivity · Project Management · Note Taking

71,668

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
68
Dependency
Built with
TypeScript88%
Updated today
Python
66%
Apache 2.0

Agent Control

AI Agents

295

An open-source runtime control plane for AI agents — define safety guardrails once, apply them across agents built on LangChain, CrewAI, Google ADK, or AWS Strands, and update controls without redeploying code.

View details
79
Repo Health
71
Technical
70
Dependency
Built with
Python66%
TypeScript33%
Updated yesterday
TypeScript
49%
AGPL 3.0

BrowserOS

Browser · AI Assistants

13,248

The open-source agentic Chromium browser with native AI agents, MCP server, and visual workflow automation — your data never leaves your machine.

View details
87
Repo Health
82
Technical
69
Dependency
Built with
TypeScript49%
Rust22%
Python16%
Updated today
TypeScript
99%
AGPL 3.0

Cherry Studio

AI Assistants

50,753

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

View details
88
Repo Health
84
Technical
71
Dependency
Built with
TypeScript99%
Updated today
C
89%
MIT

codegraph

Developer Tools · AI Code Assistants

67,011

A pre-indexed code knowledge graph that cuts AI tool calls by 58% and token costs by 16% — auto-syncing, 100% local, works with Claude Code, Cursor, Codex, and more.

View details
81
Repo Health
85
Technical
73
Dependency
Built with
C89%
Updated 1 weeks ago
TypeScript
45%
Other

Convex Backend

Developer Tools · Databases

12,394

Open-source reactive database that lets developers build live-updating apps with pure TypeScript, strong consistency, and real-time subscriptions—no separate API layer required.

View details
88
Repo Health
82
Technical
70
Dependency
Built with
TypeScript45%
Rust43%
Updated today
TypeScript
72%
Other

Epicenter

Knowledge Management · Note Taking · Developer Tools

4,761

A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.

View details
88
Repo Health
90
Technical
68
Dependency
Built with
TypeScript72%
Svelte15%
Updated today
JavaScript
51%
MIT

Ghost

CMS · Blogging

54,795

Open source headless Node.js CMS for professional publishing, paid memberships, and newsletters with a fully owned audience.

View details
96
Repo Health
85
Technical
69
Dependency
Built with
JavaScript51%
TypeScript43%
Updated today
TypeScript
92%
Other

GitNexus

Developer Tools · AI Code Assistants

45,566

Index any codebase into an interactive knowledge graph and give your AI agents deep architectural context via MCP — with zero servers required.

View details
88
Repo Health
86
Technical
74
Dependency
Built with
TypeScript92%
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