Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
edit-json-file
Advanced tools
Edit a json file with ease.
# Using npm
npm install --save edit-json-file
# Using yarn
yarn add 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("city\\.name", "anytown");
file.set("name.first", "Johnny");
file.set("name.last", "B.");
file.set("is_student", false);
//Create or append to an array
file.append("classes", "fysics");
//You can even append objects
file.append("classes", { class: "Computer Science", where: "KULeuven" });
// Output the content
console.log(file.get());
// { planet: 'Earth',
// city.name: 'anytown',
// name: { first: 'Johnny', last: 'B.' },
// is_student: false,
// classes: [
// 'fysics',
// {
// 'class': 'Computer Science',
// 'where': 'KULeuven'
// }
// ]
// }
//if you want to remove the last element from an array use pop
file.pop("classes")
// 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] } } }
There are few ways to get help:
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
.stringify_eol
(Boolean): Wheter to add the new line at the end of the file or not (default: false
)ignore_dots
(Boolean): Wheter to use the path including dots or have an object structure (default: false
)autosave
(Boolean): Save the file when setting some data in it.JsonEditor
instance.set(path, value, options)
Set a value in a specific path.
path
: The object path.value
: The value.options
: The options for set-value (applied only when {ignore_dots} file option is false)JsonEditor
instance.get(path)
Get a value in a specific path.
path
:unset(path)
Remove a path from a JSON object.
path
: The object path.JsonEditor
instance.append(path, value)
Appends a value/object to a specific path. If the path is empty it wil create a list.
path
: The object path.value
: The value.JsonEditor
instance.pop(path)
Pop an array from a specific path.
path
: The object path.JsonEditor
instance.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.empty(cb)
Empty the JSON file content.
cb
: The callback function.toString()
Get the current data as string.
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.
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
Starring and sharing the projects you like :rocket:
—I love books! I will remember you after years if you buy me one. :grin: :book:
—You can make one-time donations via PayPal. I'll probably buy a coffee tea. :tea:
—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
Bitcoin—You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! :heart:
If you are using this library in one of your projects, add it in this list. :sparkles:
@genesislcap/build-kit
@acanto/laravel-scripts
@neutralinojs/neu
@dolittle/vanir-features
@nattyjs/cli
json-config-ts
@dolittle/vanir-cli
@airbnb/nimbus
soft-add-dependencies
@spazious/ts-config
@wonderland/cli-plugin-new
@spazious/eslint-config
@spazious/storybook-config
@formbird/core
check-dependency-version-consistency
@genesislcap/foundation-cli
menreiki-init
@olmokit/cli
@williarts/williarts-commons
admooh-cli
create-web-app-template
create-fw
create-nextjs-skeleton
create-itk-app
baelte-cli
deploi
@everything-registry/sub-chunk-1554
next-templates
lyo
live-stream-radio
mobcoder-node-express-typescript-generator
modern-project-generator
nipinit
monstro
jollofjs
noir-wp-cli
semcom
sheetbase-cli
typescript-react-native-starter
@kylehue/create-app
@frdl/legacy-and-deprecations-fallback
@sevta/cli
@johnlindquist/next-lesson
@wonderland/cli-plugin-serverless
copancs-microservice-teemplate
create-ts-jest
@bemedev/npm-publish
bhc-cli
blazar-cli
bucket-cli
@bitcoin-computer/node
bt-translate
@bronzw/create-discord-js-bot
@wonderland/new
@xploration-tech/xtouch
appium-reporter-plugin
aranha-commons
express-ts-app
doggoreportbot
infinicli
intelliter
fixed-minor-patch-package-json
fluxxo-generator
@dricup/dricup-cli
react-native-dom-expo
robinhood-yolo
simple-rtg
uspk-ui
typescript-fastify-starter
uiseeds
vcommit-cli
webify-generator
@malmo/cli
@mtmeyer/create-react-figma-plugin
@imklau/react-app
zoral-generator
@postlight/node-typescript-starter-kit
@teamhive/angular-npm-seed
@something.technology/core
chakra-12345
cmd-assistant
dukecbe
d-bot-script
create-any-app
create-express-ts-api
bloggify-tools
dricup-cli
@superjs/require-auto
@shoveller/copy-package
@orhanemree/create-template
@perlatsp/devild
@panfilo/express-template
typescript-vue-starter
typescript-express-starter
@mianfrigo/express-typescript-generator
@marvinkome/create-node-app
git-normalize
env-to-now-json
guser
my-chakra-ui
@dolittle/vanir-common
menreiki2
mf-webpack-plugin
@farazahmad759/dricup-crud-express
@j.u.p.iter/jupiter-scripts
crestron-angular-theme
@benits/teste-ui
cli-json-edit
boilerplate-templify-cli
ecochat-term
@grogqli/server
@genesislcap/genx2
typescript-nest-starter
typescript-koa-starter
torder-vue-cli
@allmywallets/specification
@jianghe/sand-cli
@kcom/package-tools
srf-deploy-qb
@elastosfoundation/trinity-cli
term-of-the-day
simple-webpack-starter
@spazious/config
@sapling/cli
@rajzik/lumos
@s-ui/changelog
neu-forge
malmo
modern-node-starter
node-rg
project-initializer
@dolittle/webpack
react-vscode-cli
react-sgh-scaffolding
returrn
@chakra-ui/codemod
forcemanager-cli
feeder-cli
easybackup
lerna-from-npm
@crestron/ch5-shell-utilities-cli
dricup
h4cksterbot
gyaon-cli
def-struct
iffe-cli
jad-node-ts-kit
@triptyk/nfw-cli
create-cubicus-frontend
base-express-app-starter
axereos-hopes
blip-lang
create-nuxt-typescript-component
copancs-microservice-template
build-swan-plugin
cucu-generator
create-cubicus-backend
create-express-template
create-express-typescript-application
@bemedev/publish-command
dex-cli
deyarn
deployqb
@colorfulcompany/create-cc-jlmf
fix-package-versions
express-generator-typescript-k8s
mongoose-auto-api.cli
next-nodecms
kanuki-cli
sisback
striplet
react-easy-boilerplate
ts-express-starter
typescript-react-starter
grafpad
iffe-commit
infinitumcli
@aburkov/scripts
mtm-cli
@acanto/workflow
@deboxsoft/plop-generator
new-express-app
jollof-cli
pandocuments
lazlodb
pkgmngrgui
@hyron/cli
@anyopsos/cli
@imklau/react-boilerplate
@geesmart/zxlib
@tinyhttp/cli
@fanxie/cli
@aquestsrl/create-app-cli
create-next-library
ss-clean-slate
FAQs
Edit a json file with ease.
The npm package edit-json-file receives a total of 92,865 weekly downloads. As such, edit-json-file popularity was classified as popular.
We found that edit-json-file demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.