Strip comments from JSON. Lets you use comments in your JSON files!
This is now possible:
{
"unicorn": "cake"
}
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
Download manually or with a package-manager.
npm install --save strip-json-comments
Or globally if you want to use it as a CLI app:
npm install --global strip-json-comments
You can then use it in your Terminal like:
strip-json-comments with-comments.json > without.json
Or pipe something to it:
cat with-comments.json | strip-json-comments > without.json
bower install --save strip-json-comments
component install sindresorhus/strip-json-comments
Examples
Node.js
var stripJsonComments = require('strip-json-comments');
var json = '{//rainbows\n"unicorn":"cake"}';
JSON.parse(stripJsonComments(json));
Bower
<script src="bower_components/strip-json-comments/strip-json-comments.js"></script>
var json = '{//rainbows\n"unicorn":"cake"}';
JSON.parse(stripJsonComments(json));
API
Accepts a string with JSON and strips out the comments.
License
MIT © Sindre Sorhus