node-query/node_modules/jsdoc/node_modules/strip-json-comments
2014-11-25 14:23:08 -05:00
..
cli.js Update npm modules 2014-10-22 10:11:40 -04:00
package.json Update modules 2014-11-25 14:23:08 -05:00
readme.md Update npm modules 2014-10-22 10:11:40 -04:00
strip-json-comments.js Update npm modules 2014-10-22 10:11:40 -04:00

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 remove single-line comments // and mult-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
cat <input-file> | strip-json-comments > <output-file>

License

MIT © Sindre Sorhus