You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

edit-json-file

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edit-json-file

Edit a json file with ease.

1.8.1
latest
Source
npmnpm
Version published
Weekly downloads
170K
-1.86%
Maintainers
1
Weekly downloads
 
Created

What is edit-json-file?

The edit-json-file npm package allows you to easily read, edit, and write JSON files in a simple and straightforward manner. It provides a set of methods to manipulate JSON data without having to manually parse and stringify the JSON content.

What are edit-json-file's main functionalities?

Read JSON file

This feature allows you to read the contents of a JSON file. The `get` method retrieves the entire JSON object from the file.

const editJsonFile = require('edit-json-file');
let file = editJsonFile(`${__dirname}/data.json`);
console.log(file.get());

Set a value

This feature allows you to set a value in the JSON file. The `set` method takes a key and a value, and updates the JSON object. The `save` method writes the changes to the file.

const editJsonFile = require('edit-json-file');
let file = editJsonFile(`${__dirname}/data.json`);
file.set('name', 'John Doe');
file.save();

Unset a value

This feature allows you to remove a key-value pair from the JSON file. The `unset` method takes a key and removes it from the JSON object. The `save` method writes the changes to the file.

const editJsonFile = require('edit-json-file');
let file = editJsonFile(`${__dirname}/data.json`);
file.unset('name');
file.save();

Append to an array

This feature allows you to append a value to an array in the JSON file. The `append` method takes a key and a value, and adds the value to the array associated with the key. The `save` method writes the changes to the file.

const editJsonFile = require('edit-json-file');
let file = editJsonFile(`${__dirname}/data.json`);
file.append('items', 'newItem');
file.save();

Save the file

This feature allows you to save the changes made to the JSON file. The `save` method writes the updated JSON object back to the file.

const editJsonFile = require('edit-json-file');
let file = editJsonFile(`${__dirname}/data.json`);
file.set('name', 'John Doe');
file.save();

Other packages similar to edit-json-file

Keywords

edit

FAQs

Package last updated on 13 Feb 2025

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