Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

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

Install

npm install strip-json-comments

Usage

importstripJsonCommentsfrom'strip-json-comments';constjson=`{// 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

About

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

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors18


[8]ページ先頭

©2009-2025 Movatter.jp