5.0.1 • Published 2 years ago

strip-json-comments v5.0.1

Weekly downloads
27,822,873
License
MIT
Repository
github
Last release
2 years ago

strip-json-comments

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

This is now possible:

{
	// 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/Grunt/Broccoli plugin.

Install

npm install strip-json-comments

Usage

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

npm run bench

Related

jest-configrc@eslint/eslintrcmochatsconfig@types/strip-json-comments@huyhpham/rn-line@zhycorp/eslint-configarchetype-librarybonceeasy-select-rnuni-toolkitreact-native-bluetooth2killi8n-react-native-fast-imagepipihome@kroonprins/pipectl-corepino-pretty-js@icanpm/api-masterelectron-eslintimpetus-tslint-to-eslint-configgew-nodejs-api-clienteslint-4-fix@arisageha/react-lazyload@arisageha/react-lazyload-fix@oneplanetcrowd/developerssblog@cashremit/cr-streamline-icons@almeidaa/msuni-app-hybrid-packreact-native-template-rfbasegemini-grammarcloud-archive-s3meiroo-steedos-servercnn-cli-sharedairscanairscan-exampledas-buildbb-chatreact-native-esc-pos-sahaabrc-secure@borisovart/atol-kkt-moduledeneme323112mapineda-angular@typhonjs-node-utils/build-test@steven-torres/jsxrnative-messaging-clientmapineda-ng@ntt_app/react-native-custom-notification@sonammalhotra/lotideagreestudioeslint@smishra17/lotide@cheapthrills/lotidemapineda48-ngdiscord-music-botsreact-native-covid-sdkeasycommands-betagql_din_modmutasi-bcae2raydynamo-schematics@jttechnic/interpreter@saeon/quick-formcthpb-plugin-socialls-tester@iobroker-community-adapters/iobroker.device-watcher@olivervorasai/slidermysql-formatreact-native-printer-brothersangular-brulex-lint@belko.tech/belko-multi-wallet-sdk@newhorizon-tech/dd-npm-package-templatereact-native-shekhar-bridge-testcogoportutilsukor-remasteruncoded-connect@reversodev/oceanic-fleetdyx-reactlevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29levinodelib@nicholasjj/lotidewilscanner@khalitovadel/abstract-repository@oiti/documentoscopy-react-native@respondea/cordova-plugin-v-inappbrowser@mink-opn/build-tokensquoc-testreact-native-slider-kfunblock-block-save-variables@infinitebrahmanuniverse/nolb-strip@prodam/prodam-typescclibyarntestas212-postman-runtime-json-comment
5.0.1

2 years ago

5.0.0

3 years ago

4.0.0

4 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.1

9 years ago

2.0.0

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

12 years ago

0.1.0

12 years ago