Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

strip-json-comments

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Issues
File Explorer

Advanced tools

strip-json-comments

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

    5.0.0latest

Version published
Maintainers
1
Weekly downloads
42,493,189
decreased by-0.1%

Weekly downloads

Changelog

Source

Breaking

  • Require Node.js 14 5be749e

Improvements

  • Add option to also strip trailing commas (#59) f9a6283

https://github.com/sindresorhus/strip-json-comments/compare/v4.0.0...v5.0.0

Readme

Source

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
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

What is strip-json-comments?

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

Is strip-json-comments popular?

The npm package strip-json-comments receives a total of 34,567,867 weekly downloads. As such, strip-json-comments popularity was classified as popular.

Is strip-json-comments well maintained?

We found that strip-json-comments demonstrated a healthy version release cadence and project activity. It has 1 open source maintainer collaborating on the project.

Last updated on 22 Jul 2022
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc