Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edit-json-file

Package Overview
Dependencies
Maintainers
1
Versions
22
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.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
113K
decreased by-15.82%
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

FAQs

Package last updated on 02 Jan 2024

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc