
Security News
AI Agent Submits PR to Matplotlib, Publishes Angry Blog Post After Rejection
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.
jsonfile-commentless
Advanced tools
Easily read/write JSON files.
Writing JSON.stringify() and then fs.writeFile() and JSON.parse() with fs.readFile() enclosed in try/catch blocks became annoying. Then not being able to strip comments with the standard jsonfile package also became annoying.
npm install --save jsonfile-commentless
options (object, default undefined): Pass in any fs.readFile options or set reviver for a JSON reviver.
throws (boolean, default: true). If JSON.parse throws an error, pass this error to the callback.
If false, returns null for the object.var jsonfile = require('jsonfile-commentless')
var file = '/tmp/data.json'
jsonfile.readFile(file, function(err, obj) {
console.dir(obj)
})
options (object, default undefined): Pass in any fs.readFileSync options or set reviver for a JSON reviver.
throws (boolean, default: true). If an error is encountered reading or parsing the file, throw the error. If false, returns null for the object.var jsonfile = require('jsonfile-commentless')
var file = '/tmp/data.json'
console.dir(jsonfile.readFileSync(file))
options: Pass in any fs.writeFile options or set replacer for a JSON replacer. Can also pass in spaces and override EOL string.
var jsonfile = require('jsonfile-commentless')
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
})
formatting with spaces:
var jsonfile = require('jsonfile-commentless')
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jsonfile.writeFile(file, obj, {spaces: 2}, function(err) {
console.error(err)
})
overriding EOL:
var jsonfile = require('jsonfile-commentless')
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jsonfile.writeFile(file, obj, {spaces: 2, EOL: '\r\n'}, function(err) {
console.error(err)
})
appending to an existing JSON file:
You can use fs.writeFile option {flag: 'a'} to achieve this.
var jsonfile = require('jsonfile-commentless')
var file = '/tmp/mayAlreadyExistedData.json'
var obj = {name: 'JP'}
jsonfile.writeFile(file, obj, {flag: 'a'}, function (err) {
console.error(err)
})
options: Pass in any fs.writeFileSync options or set replacer for a JSON replacer. Can also pass in spaces and override EOL string.
var jsonfile = require('jsonfile-commentless')
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jsonfile.writeFileSync(file, obj)
formatting with spaces:
var jsonfile = require('jsonfile-commentless')
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jsonfile.writeFileSync(file, obj, {spaces: 2})
overriding EOL:
var jsonfile = require('jsonfile-commentless')
var file = '/tmp/data.json'
var obj = {name: 'JP'}
jsonfile.writeFileSync(file, obj, {spaces: 2, EOL: '\r\n'})
appending to an existing JSON file:
You can use fs.writeFileSync option {flag: 'a'} to achieve this.
var jsonfile = require('jsonfile-commentless')
var file = '/tmp/mayAlreadyExistedData.json'
var obj = {name: 'JP'}
jsonfile.writeFileSync(file, obj, {flag: 'a'})
(MIT License)
FAQs
Easily read/write JSON files. Also strips comments.
We found that jsonfile-commentless demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.

Security News
HashiCorp disclosed a high-severity RCE in next-mdx-remote affecting versions 4.3.0 to 5.x when compiling untrusted MDX on the server.

Security News
Security researchers report widespread abuse of OpenClaw skills to deliver info-stealing malware, exposing a new supply chain risk as agent ecosystems scale.