strip-json-comments

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

Github星跟踪图

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

主要指标

概览
名称与所有者sindresorhus/strip-json-comments
主编程语言JavaScript
编程语言JavaScript (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2013-11-17 15:04:17
推送于2025-05-16 20:47:24
最后一次提交
发布数19
最新版本名称v5.0.2 (发布于 2025-05-16 22:47:05)
第一版名称v0.1.0 (发布于 2013-11-17 16:05:31)
用户参与
星数608
关注者数14
派生数53
提交数80
已启用问题?
问题数34
打开的问题数1
拉请求数18
打开的拉请求数0
关闭的拉请求数10
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?