strip-json-comments

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

npm install strip-json-comments
7 442 downloads in the last day
39 880 downloads in the last week
96 176 downloads in the last month

strip-json-comments Build Status

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

This is now possible:

{
    // rainbows
    "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

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

bower install --save strip-json-comments

Component

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));
//=> {unicorn: 'cake'}

Bower

<script src="bower_components/strip-json-comments/strip-json-comments.js"></script>
var json = '{//rainbows\n"unicorn":"cake"}';
JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}

API

stripJsonComments(string)

Accepts a string with JSON and strips out the comments.

License

MIT © Sindre Sorhus

npm loves you