
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
update-json-file
Advanced tools
safely and conveniently edit the contents of a JSON file
const updateJsonFile = require('update-json-file')
const filePath = '/path/to/file/to/update.json'
updateJsonFile(filePath, (data) => {
data.abc = 123
return data
})
type Updater = (value: any) => any | Promise<any>
updateJsonFile = (
filePath: string,
updater: Updater,
options?: any
) => Promise<void>
options pass through to write-json-file
by default, throws an error if the file does not already exist
"defaultValue" option swallows load/parse errors and calls updater as though file contained this value
"defaultValue" option can be a factory function, to help avoid mutation
your updater should avoid mutating the incoming data and return a clone instead (if necessary)
Avoiding mutation when defaultValue is the same object every time:
const updateJsonFile = require('update-json-file')
const filePath = '/path/to/file/to/update.json'
const options = { defaultValue: {} }
updateJsonFile(filePath, (data) => {
// not safe to return `data`, need to return a modified clone
return Object.assign({}, data, {
abc: 123
})
}, options)
Avoiding mutation by passing a factory function as defaultValue:
const updateJsonFile = require('update-json-file')
const filePath = '/path/to/file/to/update.json'
const options = { defaultValue: () => ({}) }
updateJsonFile(filePath, (data) => {
// factory function is run each time, so `data` is a new object each time
data.abc = 123
return data
}, options)
FAQs
safely and conveniently edit the contents of a JSON file
The npm package update-json-file receives a total of 3,039 weekly downloads. As such, update-json-file popularity was classified as popular.
We found that update-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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.