strip-json-comments

Strip comments from JSON. Lets you use comments in your JSON files!

Github stars Tracking Chart

strip-json-comments Build Status

Strip comments from JSON. Lets you use comments in your JSON files!

This is now possible:

{
	// Rainbows
	"unicorn": /* ❤ */ "cake"
}

It will replace single-line comments // and multi-line comments /**/ with whitespace. This allows JSON error positions to remain as close as possible to the original source.

Also available as a Gulp/Grunt/Broccoli plugin.

Install

$ npm install strip-json-comments

Usage

const json = `{
	// Rainbows
	"unicorn": /* ❤ */ "cake"
}`;

JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}

API

stripJsonComments(jsonString, options?)

jsonString

Type: string

Accepts a string with JSON and returns a string without comments.

options

Type: object

whitespace

Type: boolean
Default: true

Replace comments with whitespace instead of stripping them entirely.

Benchmark

$ npm run bench

Main metrics

Overview
Name With Ownersindresorhus/strip-json-comments
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2013-11-17 15:04:17
Pushed At2025-05-16 20:47:24
Last Commit At
Release Count19
Last Release Namev5.0.2 (Posted on 2025-05-16 22:47:05)
First Release Namev0.1.0 (Posted on 2013-11-17 16:05:31)
用户参与
Stargazers Count608
Watchers Count14
Fork Count53
Commits Count80
Has Issues Enabled
Issues Count34
Issue Open Count1
Pull Requests Count18
Pull Requests Open Count0
Pull Requests Close Count10
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private