# strip-json-comments

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

Latest version **5.0.3** (published 2025-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install strip-json-comments
pnpm add strip-json-comments
yarn add strip-json-comments
bun add strip-json-comments
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.3 |
| Published | 2025-08-08 |
| First published | 2013-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=14.16 |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 625 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | json, strip, comments, remove, delete, trim, multiline, parse, config, configuration, settings, util, env, environment, jsonc |

## Links

- npm: https://www.npmjs.com/package/strip-json-comments
- Repository: https://github.com/sindresorhus/strip-json-comments
- Homepage: https://github.com/sindresorhus/strip-json-comments#readme
- Issues: https://github.com/sindresorhus/strip-json-comments/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/strip-json-comments

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 5.0.3 (latest) — 2025-08-08
- 5.0.2 — 2025-05-16
- 5.0.1 — 2023-07-04
- 5.0.0 — 2022-07-22
- 4.0.0 — 2021-08-19
- 3.1.1 — 2020-07-12
- 3.1.0 — 2020-04-06
- 3.0.1 — 2019-04-30
- 3.0.0 — 2019-04-30
- 2.0.1 — 2016-02-09
- 2.0.0 — 2015-11-18
- 1.0.4 — 2015-08-02
- 1.0.3 — 2015-08-01
- 1.0.2 — 2014-10-16
- 1.0.1 — 2014-07-26
- … 5 more at https://npm.io/package/strip-json-comments/versions

## README

# 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

```sh
npm install strip-json-comments
```

## Usage

```js
import stripJsonComments from 'strip-json-comments';

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`

##### trailingCommas

Type: `boolean`\
Default: `false`

Strip trailing commas in addition to comments.

##### whitespace

Type: `boolean`\
Default: `true`

Replace comments and trailing commas with whitespace instead of stripping them entirely.

## Benchmark

```sh
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

---
_Source: https://npm.io/package/strip-json-comments · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
