strip-json-comments ![Build Status](https://camo.githubusercontent.com/596b9d3d199957dd553a84b9592d4d65817f3004ab28c346bb2168eda4d5c26b/68747470733a2f2f7472617669732d63692e6f72672f73696e647265736f726875732f73747269702d6a736f6e2d636f6d6d656e74732e7376673f6272616e63683d6d6173746572)
Strip comments from JSON. Lets you use comments in your JSON files!
This is now possible:
{
// rainbows
"unicorn": /* ❤ */ "cake"
}
It will remove single-line comments //
and multi-line comments /**/
.
Also available as a gulp/grunt/broccoli plugin and a require hook.
There's already json-comments, but it's only for Node.js and uses a naive regex to strip comments which fails on simple cases like {"a":"//"}
. This module however parses out the comments.
Install
$ npm install --save strip-json-comments
$ bower install --save strip-json-comments
$ component install sindresorhus/strip-json-comments
Usage
var json = '{/*rainbows*/"unicorn":"cake"}';
JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}
API
stripJsonComments(input)
input
Type: string
Accepts a string with JSON and returns a string without comments.
CLI
$ npm install --global strip-json-comments
$ strip-json-comments --help
strip-json-comments input-file > output-file
# or
strip-json-comments < input-file > output-file
Related
License
MIT © Sindre Sorhus