mirror of https://github.com/nodejs/node.git
f9dd34d301
PR-URL: https://github.com/iojs/io.js/pull/1539 Fixes: https://github.com/iojs/io.js/issues/1253 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> |
||
---|---|---|
.. | ||
cli.js | ||
package.json | ||
readme.md | ||
strip-json-comments.js |
readme.md
strip-json-comments
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
License
MIT © Sindre Sorhus