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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?