
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
replace-json-property
Advanced tools
This module allows you to replace a specific property in a JSON.
Table of Contents generated with DocToc
You can use this via the following command:
replace-json-property pathToFile property value
This command replaces all occurences of the matching property. It also replaces occurences in nested objects or objects in arrays.
The following command would replace all values of the foo
property with 'test' inside the test.json
.
replace-json-property ./test.json foo test,
Executing the command above on the given JSON
{
"foo": "bar",
"a": {
"b": 1,
"foo": "bar",
"c": [
{"d": 1, "foo": "bar"},
{"d": 2, "foo": "bar"},
{"d": 3, "foo": "bar"},
]
}
}
results in:
{
"foo": "test",
"a": {
"b": 1,
"foo": "test",
"c": [
{"d": 1, "foo": "test"},
{"d": 2, "foo": "test"},
{"d": 3, "foo": "test"},
]
}
}
All commands explained above can also be run with the shortcut version rjp
.
rjp ./test.json foo test,
You can also use the replace function in your JavaScript code.
Using module imports
import {replace} from 'replace-json-property';
replace('./environment/test.json', 'foo', 'new value');
Using commonjs
const replaceJSONProperty = require('replace-json-property');
replaceJSONProperty.replace('./environment/test.json', 'foo', 'new value');
The following flags allow you to configure how the resulting file is written.
Option | Description | Default |
---|---|---|
-s or --spaces | Add the spaces the file should be written with, for example (2, 4) | 2 |
-e or --eol | Add the line ending the file should be written with, for example "\r\n" | "\n" |
--silent | Silent mode. Executes without log messages | False |
--limit | Limit the number of replacements | 0 (unlimited) |
--add | When set to true propertys that do not exist will be added | false |
You can always run the help command to see how the signature looks
replace-json-property -h
or
replace-json-property --help
To get the current version use the --version or -v command.
FAQs
CLI tool to replace a property in a JSON file
The npm package replace-json-property receives a total of 12,211 weekly downloads. As such, replace-json-property popularity was classified as popular.
We found that replace-json-property 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.