• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# strip-json-comments [![Build Status](https://travis-ci.org/sindresorhus/strip-json-comments.svg?branch=master)](https://travis-ci.org/sindresorhus/strip-json-comments)
2
3> Strip comments from JSON. Lets you use comments in your JSON files!
4
5This is now possible:
6
7```js
8{
9	// rainbows
10	"unicorn": /* ❤ */ "cake"
11}
12```
13
14It will replace single-line comments `//` and multi-line comments `/**/` with whitespace. This allows JSON error positions to remain as close as possible to the original source.
15
16Also available as a [gulp](https://github.com/sindresorhus/gulp-strip-json-comments)/[grunt](https://github.com/sindresorhus/grunt-strip-json-comments)/[broccoli](https://github.com/sindresorhus/broccoli-strip-json-comments) plugin.
17
18
19## Install
20
21```
22$ npm install --save strip-json-comments
23```
24
25
26## Usage
27
28```js
29const json = '{/*rainbows*/"unicorn":"cake"}';
30
31JSON.parse(stripJsonComments(json));
32//=> {unicorn: 'cake'}
33```
34
35
36## API
37
38### stripJsonComments(input, [options])
39
40#### input
41
42Type: `string`
43
44Accepts a string with JSON and returns a string without comments.
45
46#### options
47
48##### whitespace
49
50Type: `boolean`
51Default: `true`
52
53Replace comments with whitespace instead of stripping them entirely.
54
55
56## Related
57
58- [strip-json-comments-cli](https://github.com/sindresorhus/strip-json-comments-cli) - CLI for this module
59- [strip-css-comments](https://github.com/sindresorhus/strip-css-comments) - Strip comments from CSS
60
61
62## License
63
64MIT © [Sindre Sorhus](http://sindresorhus.com)
65