Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
edit-json-file
Advanced tools
Edit a json file with ease.
$ npm i --save edit-json-file
const editJsonFile = require("edit-json-file");
// If the file doesn't exist, the content will be an empty object by default.
let file = editJsonFile(`${__dirname}/foo.json`);
// Set a couple of fields
file.set("planet", "Earth");
file.set("name.first", "Johnny");
file.set("name.last", "B.");
file.set("is_student", false);
// Output the content
console.log(file.get());
// { planet: 'Earth',
// name: { first: 'Johnny', last: 'B.' },
// is_student: false }
// Save the data to the disk
file.save();
// Reload it from the disk
file = editJsonFile(`${__dirname}/foo.json`, {
autosave: true
});
// Get one field
console.log(file.get("name.first"));
// => Johnny
// This will save it to disk
file.set("a.new.field.as.object", {
hello: "world"
});
// Output the whole thing
console.log(file.toObject());
// { planet: 'Earth',
// name: { first: 'Johnny', last: 'B.' },
// is_student: false,
// a: { new: { field: [Object] } } }
JsonEditor(path, options)
path
: The path to the JSON file.options
: An object containing the following fields:stringify_width
(Number): The JSON stringify indent width (default: 2
).stringify_fn
(Function): A function used by JSON.stringify
.autosave
(Boolean): Save the file when setting some data in it.JsonEditor
instance.set(path, value)
Set a value in a specific path.
path
: The object path.value
: The value.JsonEditor
instance.get(path)
Get a value in a specific path.
path
:read(cb)
Read the JSON file.
cb
: An optional callback function which will turn the function into an asynchronous one.read(The, cb)
write Write the JSON file.
The
: file content.cb
: An optional callback function which will turn the function into an asynchronous one.JsonEditor
instance.save(cb)
Save the file back to disk.
cb
: An optional callback function which will turn the function into an asynchronous one.JsonEditor
instance.toObject()
editJsonFile(path, options)
Edit a json file.
path
: The path to the JSON file.options
: An object containing the following fields:JsonEditor
instance.Have an idea? Found a bug? See how to contribute.
Another way to support the development of my open-source modules is to set up a recurring donation, via Patreon. :rocket:
PayPal donations are appreciated too! Each dollar helps.
Thanks! :heart:
FAQs
Edit a json file with ease.
The npm package edit-json-file receives a total of 95,869 weekly downloads. As such, edit-json-file popularity was classified as popular.
We found that edit-json-file 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.