jsonc-parser
A fault-tolerant scanner and parser for JSONC (JSON with comments), with SAX-style visiting, DOM trees, and edit APIs.
Repository Health
Technical Analysis
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 (Nodetree) with offsets, plusfindNodeAtLocation/findNodeAtOffset/getLocationhelpers to navigate itformat()andmodify()APIs that compute textual edit operations instead of requiring full re-serializationstripComments()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 Quality — src/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
AFFiNE
Productivity · Project Management · Note Taking
Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.
Agent Control
AI Agents
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.
BrowserOS
Browser · AI Assistants
The open-source agentic Chromium browser with native AI agents, MCP server, and visual workflow automation — your data never leaves your machine.
Cherry Studio
AI Assistants
All-in-one AI desktop client with 300+ assistants and multi-model support
codegraph
Developer Tools · AI Code Assistants
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.
Convex Backend
Developer Tools · Databases
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.
Epicenter
Knowledge Management · Note Taking · Developer Tools
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.
Ghost
CMS · Blogging
Open source headless Node.js CMS for professional publishing, paid memberships, and newsletters with a fully owned audience.
GitNexus
Developer Tools · AI Code Assistants
Index any codebase into an interactive knowledge graph and give your AI agents deep architectural context via MCP — with zero servers required.