Socket
Socket
Sign inDemoInstall

strip-json-comments

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strip-json-comments

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


Version published
Weekly downloads
54M
decreased by-0.61%
Maintainers
1
Install size
5.96 kB
Created
Weekly downloads
 

Package description

What is strip-json-comments?

The strip-json-comments package allows you to strip comments from JSON content, making it possible to use comments in JSON files or strings for development purposes without violating the JSON format specification. This can be particularly useful for configuration files or complex JSON data where comments can provide valuable context or instructions.

What are strip-json-comments's main functionalities?

Strip comments from JSON string

This feature allows you to remove both line (//) and block (/* */) comments from a JSON string, making it a valid JSON format. The code sample demonstrates how to use the package to strip comments from a JSON string containing both types of comments.

"use strict";\nconst stripJsonComments = require('strip-json-comments');\n\nconst jsonWithComments = '{\n\t// This is a comment\n\t"foo": true\n}';\nconst cleanedJson = stripJsonComments(jsonWithComments);\n\nconsole.log(cleanedJson); // {\n\t\"foo\": true\n}"

Other packages similar to strip-json-comments

Readme

Source

strip-json-comments Build Status

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

This is now possible:

{
	// rainbows
	"unicorn": /* ❤ */ "cake"
}

There's already json-comments, but it's only for Node.js and uses a naive regex to strip comments which fails on simple cases like {"a":"//"}. This module however parses out the comments.

Install

Download manually or with a package-manager.

npm
npm install --save strip-json-comments

Or globally if you want to use it as a CLI app:

npm install --global strip-json-comments

You can then use it in your Terminal like:

strip-json-comments with-comments.json > without.json

Or pipe something to it:

cat with-comments.json | strip-json-comments > without.json
Bower
bower install --save strip-json-comments
Component
component install sindresorhus/strip-json-comments

Examples

Node.js

var stripJsonComments = require('strip-json-comments');
var json = '{//rainbows\n"unicorn":"cake"}';
JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}

Bower

<script src="bower_components/strip-json-comments/strip-json-comments.js"></script>
var json = '{//rainbows\n"unicorn":"cake"}';
JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}

API

stripJsonComments(string)

Accepts a string with JSON and strips out the comments.

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 17 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc