strip-json-comments
    Overview
    Documentation
    Tutorials
    Insights
    Code
    Dependencies
    Contributors
    Jobs

strip-json-comments

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

3.0.1  •  Updated 1 years 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

Popularity

Weekly Downloads
10.5M
Stars
437

Maintenance

Development

Last ver 1 year ago
Created 6 years ago
Last commit 10 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
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
FacebookTwitterLinkedIn
© 2020 Devstore, Inc.