Sha256: 0bdbc4063db0dfbd60d8b47c931a37bfa8bbdd1caa86842ba5ea43896c4a0f8f

Contents?: true

Size: 1.92 KB

Versions: 81

Compression:

Stored size: 1.92 KB

Contents

# strip-json-comments [![Build Status](https://travis-ci.com/sindresorhus/strip-json-comments.svg?branch=master)](https://travis-ci.com/github/sindresorhus/strip-json-comments)

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

This is now possible:

```js
{
	// Rainbows
	"unicorn": /* ❤ */ "cake"
}
```

It 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.

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.

## Install

```
$ npm install strip-json-comments
```

## Usage

```js
const json = `{
	// Rainbows
	"unicorn": /* ❤ */ "cake"
}`;

JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}
```

## API

### stripJsonComments(jsonString, options?)

#### jsonString

Type: `string`

Accepts a string with JSON and returns a string without comments.

#### options

Type: `object`

##### whitespace

Type: `boolean`\
Default: `true`

Replace comments with whitespace instead of stripping them entirely.

## Benchmark

```
$ npm run bench
```

## Related

- [strip-json-comments-cli](https://github.com/sindresorhus/strip-json-comments-cli) - CLI for this module
- [strip-css-comments](https://github.com/sindresorhus/strip-css-comments) - Strip comments from CSS

---

<div align="center">
	<b>
		<a href="https://tidelift.com/subscription/pkg/npm-strip-json-comments?utm_source=npm-strip-json-comments&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
	</b>
	<br>
	<sub>
		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
	</sub>
</div>

Version data entries

81 entries across 63 versions & 4 rubygems

Version Path
immosquare-cleaner-0.1.68 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.67 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.66 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.65 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.64 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.63 node_modules/strip-json-comments/readme.md
rapid_stack-0.2.0 templates/frontend/node_modules/strip-json-comments/readme.md
rapid_stack-0.1.1 templates/FrontEnd/node_modules/strip-json-comments/readme.md
rapid_stack-0.1.0 templates/FrontEnd/node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.62 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.61 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.60 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.59 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.58 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.57 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.56 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.55 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.54 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.53 node_modules/strip-json-comments/readme.md
immosquare-cleaner-0.1.52 node_modules/strip-json-comments/readme.md