Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
strip-json-comments
Advanced tools
Strip comments from JSON. Lets you use comments in your JSON files!
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.
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}"
json5 is a package that extends the JSON format to include some ECMAScript 5.1 features, such as comments, trailing commas, and more. While it offers a broader scope of features beyond just stripping comments, it can be used for a similar purpose of handling JSON data with comments.
jsonc-parser is a parser that handles JSONC (JSON with Comments) format. It is designed to parse and manipulate JSONC data, offering functionality to strip comments as part of its parsing process. Compared to strip-json-comments, jsonc-parser provides a more comprehensive parsing and manipulation toolset for JSONC.
Strip comments from JSON. Lets you use comments in your JSON files!
This is now possible:
{
// rainbows
"unicorn": /* ❤ */ "cake"
}
It will remove single-line comments //
and mult-line comments /**/
.
Also available as a gulp/grunt/broccoli plugin and a require hook.
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.
$ npm install --save strip-json-comments
$ bower install --save strip-json-comments
$ component install sindresorhus/strip-json-comments
var json = '{/*rainbows*/"unicorn":"cake"}';
JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}
Type: string
Accepts a string with JSON and returns a string without comments.
$ npm install --global strip-json-comments
$ strip-json-comments --help
strip-json-comments <input-file> > <output-file>
# or
cat <input-file> | strip-json-comments > <output-file>
MIT © Sindre Sorhus
FAQs
Strip comments from JSON. Lets you use comments in your JSON files!
The npm package strip-json-comments receives a total of 35,766,998 weekly downloads. As such, strip-json-comments popularity was classified as popular.
We found that strip-json-comments demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.