336523243e6c0d930160c07f3df63c034f78fdbe
[platform/framework/web/crosswalk-tizen.git] /
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
5 This is now possible:
6
7 ```js
8 {
9         // rainbows
10         "unicorn": /* ❤ */ "cake"
11 }
12 ```
13
14 It will remove single-line comments `//` and multi-line comments `/**/`.
15
16 Also 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 and a [require hook](https://github.com/uTest/autostrip-json-comments).
17
18
19 *There's already [json-comments](https://npmjs.org/package/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.*
20
21
22 ## Install
23
24 ```sh
25 $ npm install --save strip-json-comments
26 ```
27
28 ```sh
29 $ bower install --save strip-json-comments
30 ```
31
32 ```sh
33 $ component install sindresorhus/strip-json-comments
34 ```
35
36
37 ## Usage
38
39 ```js
40 var json = '{/*rainbows*/"unicorn":"cake"}';
41 JSON.parse(stripJsonComments(json));
42 //=> {unicorn: 'cake'}
43 ```
44
45
46 ## API
47
48 ### stripJsonComments(input)
49
50 #### input
51
52 Type: `string`
53
54 Accepts a string with JSON and returns a string without comments.
55
56
57 ## CLI
58
59 ```sh
60 $ npm install --global strip-json-comments
61 ```
62
63 ```sh
64 $ strip-json-comments --help
65
66 strip-json-comments input-file > output-file
67 # or
68 strip-json-comments < input-file > output-file
69 ```
70
71
72 ## License
73
74 MIT © [Sindre Sorhus](http://sindresorhus.com)