strip-json-comments

Strip comments from JSON strings so you can safely use JSONC config files.

Library
npm
v5.0.3
626stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
39/100Needs Attention
Development Activity0
Maintenance20
Community56
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture70
Code Quality78
Innovation55
Learning Curve85

strip-json-comments removes // and /* */ style comments (and optionally trailing commas) from JSON strings before parsing, letting you author human-friendly JSONC configuration files while still producing standards-compliant JSON.parse() output. It preserves character offsets by replacing stripped comments with whitespace by default, so error positions reported by JSON.parse() still point at the original source location, which matters when debugging a malformed config file.

What You Get

  • A single default export, stripJsonComments(), that takes a JSON string and returns a clean JSON string
  • Support for both // single-line and /* */ multi-line comment styles inside JSON
  • An optional trailingCommas flag to also strip trailing commas before parsing
  • A whitespace option to choose between blanking comments (preserving character offsets) or fully removing them

Common Use Cases

  • Reading a JSONC config file (e.g. tsconfig.json-style files) and parsing it as regular JSON
  • Building a config-loading layer for a CLI tool or app that wants to let users comment their JSON settings
  • Powering higher-level JSONC parsers and editors that need to tolerate comments in JSON

Under The Hood

Architecture: The entire library is a single exported function, stripJsonComments(), that walks the input string one character at a time with a small state machine (isInsideString / isInsideComment as singleComment or multiComment via Symbols) plus an offset/buffer pair used to flush non-comment slices as it goes; an optional second pass handles trailingCommas by tracking the last seen comma index and only stripping it once a closing } or ] confirms it was trailing. Tech Stack: Pure, dependency-free modern JavaScript (ESM only, type: module, Node >=14.16) with hand-written .d.ts type definitions, tested with ava and type-checked with tsd; xo enforces lint rules and matcha runs the benchmark script. Code Quality: test.js exercises single-line comments, multi-line comments, comments inside strings, escaped quotes, both whitespace modes, and the trailingCommas option; the code favors small pure functions (isEscaped, stripWithWhitespace, stripWithoutWhitespace) over classes, with no external error-handling surface beyond a single TypeError guard on the input type. API Design: The API is minimal and ergonomic, one default export plus two boolean options (whitespace, trailingCommas) with sensible defaults, requiring zero configuration for the common case of import stripJsonComments from ‘strip-json-comments’.

Used by 5 apps in this directory

TypeScript
95%
Apache 2.0

AionUi

AI Agents · Productivity

32,622

Free, open-source Cowork desktop app that unifies Claude Code, Codex, Gemini CLI, and 20+ AI agents into a single platform with multi-agent teams, 24/7 cron automation, and zero-config built-in agent.

View details
87
Repo Health
76
Technical
66
Dependency
Built with
TypeScript95%
Updated 5 days ago
JavaScript
90%
Other

CodeSandbox

Code Editors · Developer Tools

13,640

Instantly ready browser-based IDE that runs full npm dependency resolution and transpilation entirely client-side, with no server needed.

View details
69
Repo Health
76
Technical
62
Dependency
Built with
JavaScript90%
Updated 1 weeks ago
TypeScript
99%
Apache 2.0

Mastra Code

AI Code Assistants

27,743

"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.

View details
88
Repo Health
73
Technical
65
Dependency
Built with
TypeScript99%
Updated today
TypeScript
99%
Other

Sourcebot

Search · Developer Tools · AI Code Assistants

3,930

A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.

View details
85
Repo Health
83
Technical
65
Dependency
Built with
TypeScript99%
Updated 2 days ago
TypeScript
85%
Other

Webiny JS

Ecommerce · Blogging · CMS

8,032

Open-source, self-hosted CMS on AWS serverless — a TypeScript framework you extend with code, not a product you configure through a UI.

View details
90
Repo Health
86
Technical
62
Dependency
Built with
TypeScript85%
JavaScript14%
Updated yesterday

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