strip-json-comments
    Overview
    Documentation
    Insights
    Code
    Contributors
    Dependencies
    Alternatives

strip-json-comments

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

3.0.1  •  Updated 9 months ago  •  by Sindre Sorhus  •  MIT License

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

Related

License

MIT © Sindre Sorhus

How often do you use dark themes on other websites?

Popularity

Weekly Downloads
10.5M
Stars
437

Maintenance

Development

Last ver 9 months ago
Created 6 years ago
Last commit 8 months ago
1 month between commits

Technology

Node version: 8.16.0
6.3K unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

16 contributors
Sindre Sorhus
Maintainer, 45 commits, 12 merges
Xof Nagem
4 commits
Simon Lydell
2 commits, 3 PRs
Works at Insurello
Blake Embrey
Maintainer, 1 commits, 1 PRs
Works at opendoor-labs
Kevin Martensson
Maintainer, 1 commits
Works at imagemin yeoman
Sam Verschueren
Maintainer, 1 merges

Tags

json
strip
comments
remove
delete
trim
multiline
parse
config
configuration
settings
util
env
environment
Ready for the next level?
Join Openbase's founding team to help us build the ultimate open-source app store, work with the latest technologies, and enjoy great culture, impact and autonomy
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
© 2020 Devstore, Inc.