{"id":13700348,"url":"https://github.com/IonicaBizau/edit-json-file","last_synced_at":"2025-05-04T18:34:57.921Z","repository":{"id":38431981,"uuid":"71233145","full_name":"IonicaBizau/edit-json-file","owner":"IonicaBizau","description":"Edit a json file with ease.","archived":false,"fork":false,"pushed_at":"2025-02-13T19:03:04.000Z","size":71,"stargazers_count":98,"open_issues_count":3,"forks_count":27,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-24T20:07:59.044Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IonicaBizau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"ionicabizau","patreon":"ionicabizau","open_collective":"ionicabizau","custom":"https://www.buymeacoffee.com/h96wwchmy"}},"created_at":"2016-10-18T09:44:16.000Z","updated_at":"2025-04-11T00:30:23.000Z","dependencies_parsed_at":"2024-06-18T13:33:47.075Z","dependency_job_id":"a74488b7-1866-4817-82aa-2859be007636","html_url":"https://github.com/IonicaBizau/edit-json-file","commit_stats":{"total_commits":95,"total_committers":12,"mean_commits":7.916666666666667,"dds":"0.33684210526315794","last_synced_commit":"ad0957724a920d72384769a441c3bd4352625031"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IonicaBizau%2Fedit-json-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IonicaBizau%2Fedit-json-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IonicaBizau%2Fedit-json-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IonicaBizau%2Fedit-json-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IonicaBizau","download_url":"https://codeload.github.com/IonicaBizau/edit-json-file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252383168,"owners_count":21739285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-08-02T20:00:54.538Z","updated_at":"2025-05-04T18:34:52.908Z","avatar_url":"https://github.com/IonicaBizau.png","language":"JavaScript","funding_links":["https://github.com/sponsors/ionicabizau","https://patreon.com/ionicabizau","https://opencollective.com/ionicabizau","https://www.buymeacoffee.com/h96wwchmy","https://www.buymeacoffee.com/H96WwChMy","https://www.patreon.com/ionicabizau","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=RVXDDLKKLQRJW"],"categories":[":package: NodeJS"],"sub_categories":["JSON"],"readme":"\u003c!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. --\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# edit-json-file\n\n [![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/edit-json-file.svg)](https://www.npmjs.com/package/edit-json-file) [![Downloads](https://img.shields.io/npm/dt/edit-json-file.svg)](https://www.npmjs.com/package/edit-json-file) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github\u0026utm_medium=button\u0026utm_term=johnnyb\u0026utm_campaign=github)\n\n\u003ca href=\"https://www.buymeacoffee.com/H96WwChMy\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png\" alt=\"Buy Me A Coffee\"\u003e\u003c/a\u003e\n\n\n\n\n\n\n\n\u003e Edit a json file with ease.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## :cloud: Installation\n\n```sh\n# Using npm\nnpm install --save edit-json-file\n\n# Using yarn\nyarn add edit-json-file\n```\n\n\n\n\n\n\n\n\n\n\n\n\n\n## :clipboard: Example\n\n\n\n```js\nconst editJsonFile = require(\"edit-json-file\");\n\n// If the file doesn't exist, the content will be an empty object by default.\nlet file = editJsonFile(`${__dirname}/foo.json`);\n\n// Set a couple of fields\nfile.set(\"planet\", \"Earth\");\nfile.set(\"city\\\\.name\", \"anytown\");\nfile.set(\"name.first\", \"Johnny\");\nfile.set(\"name.last\", \"B.\");\nfile.set(\"is_student\", false);\n//Create or append to an array\nfile.append(\"classes\", \"fysics\");\n//You can even append objects\nfile.append(\"classes\", { class: \"Computer Science\", where: \"KULeuven\" });\n\n\n// Output the content\nconsole.log(file.get());\n// { planet: 'Earth',\n//   city.name: 'anytown',\n//   name: { first: 'Johnny', last: 'B.' },\n//   is_student: false,\n//   classes: [\n//     'fysics',\n//     {\n//       'class': 'Computer Science',\n//       'where': 'KULeuven'\n//     }\n//   ]\n// }\n\n//if you want to remove the last element from an array use pop\nfile.pop(\"classes\")\n\n// Save the data to the disk\nfile.save();\n\n// Reload it from the disk\nfile = editJsonFile(`${__dirname}/foo.json`, {\n    autosave: true\n});\n\n// Get one field\nconsole.log(file.get(\"name.first\"));\n// =\u003e Johnny\n\n// This will save it to disk\nfile.set(\"a.new.field.as.object\", {\n    hello: \"world\"\n});\n\n// Output the whole thing\nconsole.log(file.toObject());\n// { planet: 'Earth',\n//   name: { first: 'Johnny', last: 'B.' },\n//   is_student: false,\n//   a: { new: { field: [Object] } } }\n```\n\n\n\n\n\n\n\n\n\n\n\n## :question: Get Help\n\nThere are few ways to get help:\n\n\n\n 1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.\n 2. For bug reports and feature requests, open issues. :bug:\n 3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:\n\n\n\n\n\n## :memo: Documentation\n\n\n### `JsonEditor(path, options)`\n\n#### Params\n\n- **String** `path`: The path to the JSON file.\n- **Object** `options`: An object containing the following fields:\n - `stringify_width` (Number): The JSON stringify indent width (default: `2`).\n - `stringify_fn` (Function): A function used by `JSON.stringify`.\n - `stringify_eol` (Boolean): Wheter to add the new line at the end of the file or not (default: `false`)\n - `ignore_dots` (Boolean): Wheter to use the path including dots or have an object structure (default: `false`)\n - `autosave` (Boolean): Save the file when setting some data in it.\n\n#### Return\n- **JsonEditor** The `JsonEditor` instance.\n\n### `set(path, value, options)`\nSet a value in a specific path.\n\n#### Params\n\n- **String** `path`: The object path.\n- **Anything** `value`: The value.\n- **Object** `options`: The options for set-value (applied only when {ignore_dots} file option is false)\n\n#### Return\n- **JsonEditor** The `JsonEditor` instance.\n\n### `get(path)`\nGet a value in a specific path.\n\n#### Params\n\n- **String** `path`:\n\n#### Return\n- **Value** The object path value.\n\n### `unset(path)`\nRemove a path from a JSON object.\n\n#### Params\n\n- **String** `path`: The object path.\n\n#### Return\n- **JsonEditor** The `JsonEditor` instance.\n\n### `append(path, value)`\nAppends a value/object to a specific path.\nIf the path is empty it wil create a list.\n\n#### Params\n\n- **String** `path`: The object path.\n- **Anything** `value`: The value.\n\n#### Return\n- **JsonEditor** The `JsonEditor` instance.\n\n### `pop(path)`\nPop an array from a specific path.\n\n#### Params\n\n- **String** `path`: The object path.\n\n#### Return\n- **JsonEditor** The `JsonEditor` instance.\n\n### `read(cb)`\nRead the JSON file.\n\n#### Params\n\n- **Function** `cb`: An optional callback function which will turn the function into an asynchronous one.\n\n#### Return\n- **Object** The object parsed as object or an empty object by default.\n\n### `read(The, cb)`\nwrite\nWrite the JSON file.\n\n#### Params\n\n- **String** `The`: file content.\n- **Function** `cb`: An optional callback function which will turn the function into an asynchronous one.\n\n#### Return\n- **JsonEditor** The `JsonEditor` instance.\n\n### `empty(cb)`\nEmpty the JSON file content.\n\n#### Params\n\n- **Function** `cb`: The callback function.\n\n### `toString()`\nGet the current data as string.\n\n#### Return\n- **string** The data as string.\n\n### `save(cb)`\nSave the file back to disk.\n\n#### Params\n\n- **Function** `cb`: An optional callback function which will turn the function into an asynchronous one.\n\n#### Return\n- **JsonEditor** The `JsonEditor` instance.\n\n### `toObject()`\n\n#### Return\n- **Object** The data object.\n\n### `editJsonFile(path, options)`\nEdit a json file.\n\n#### Params\n\n- **String** `path`: The path to the JSON file.\n- **Object** `options`: An object containing the following fields:\n\n#### Return\n- **JsonEditor** The `JsonEditor` instance.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## :yum: How to contribute\nHave an idea? Found a bug? See [how to contribute][contributing].\n\n\n## :sparkling_heart: Support my projects\nI open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,\nthis 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).\n\nHowever, 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:\n\n\n - Starring and sharing the projects you like :rocket:\n - [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book:\n - [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:\n - [![Support me on Patreon][badge_patreon]][patreon]—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).\n - **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`\n\n    ![](https://i.imgur.com/z6OQI95.png)\n\n\nThanks! :heart:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## :dizzy: Where is this library used?\nIf you are using this library in one of your projects, add it in this list. :sparkles:\n\n - `@genesislcap/build-kit`\n - `@acanto/laravel-scripts`\n - `@neutralinojs/neu`\n - `@dolittle/vanir-features`\n - `@nattyjs/cli`\n - `json-config-ts`\n - `@dolittle/vanir-cli`\n - `@airbnb/nimbus`\n - `soft-add-dependencies`\n - `@spazious/ts-config`\n - `@wonderland/cli-plugin-new`\n - `@spazious/eslint-config`\n - `@spazious/storybook-config`\n - `@formbird/core`\n - `check-dependency-version-consistency`\n - `@genesislcap/foundation-cli`\n - `menreiki-init`\n - `@olmokit/cli`\n - `@williarts/williarts-commons`\n - `admooh-cli`\n - `create-web-app-template`\n - `create-fw`\n - `create-nextjs-skeleton`\n - `create-itk-app`\n - `baelte-cli`\n - `deploi`\n - `@everything-registry/sub-chunk-1554`\n - `next-templates`\n - `lyo`\n - `live-stream-radio`\n - `mobcoder-node-express-typescript-generator`\n - `modern-project-generator`\n - `nipinit`\n - `monstro`\n - `jollofjs`\n - `noir-wp-cli`\n - `semcom`\n - `sheetbase-cli`\n - `typescript-react-native-starter`\n - `@kylehue/create-app`\n - `@frdl/legacy-and-deprecations-fallback`\n - `@sevta/cli`\n - `@johnlindquist/next-lesson`\n - `@wonderland/cli-plugin-serverless`\n - `copancs-microservice-teemplate`\n - `create-ts-jest`\n - `@bemedev/npm-publish`\n - `bhc-cli`\n - `blazar-cli`\n - `bucket-cli`\n - `@bitcoin-computer/node`\n - `bt-translate`\n - `@bronzw/create-discord-js-bot`\n - `@wonderland/new`\n - `@xploration-tech/xtouch`\n - `appium-reporter-plugin`\n - `aranha-commons`\n - `express-ts-app`\n - `doggoreportbot`\n - `infinicli`\n - `intelliter`\n - `fixed-minor-patch-package-json`\n - `fluxxo-generator`\n - `@dricup/dricup-cli`\n - `react-native-dom-expo`\n - `robinhood-yolo`\n - `simple-rtg`\n - `uspk-ui`\n - `typescript-fastify-starter`\n - `uiseeds`\n - `vcommit-cli`\n - `webify-generator`\n - `@malmo/cli`\n - `@mtmeyer/create-react-figma-plugin`\n - `@imklau/react-app`\n - `zoral-generator`\n - `@postlight/node-typescript-starter-kit`\n - `@teamhive/angular-npm-seed`\n - `@something.technology/core`\n - `chakra-12345`\n - `cmd-assistant`\n - `dukecbe`\n - `d-bot-script`\n - `create-any-app`\n - `create-express-ts-api`\n - `bloggify-tools`\n - `dricup-cli`\n - `@superjs/require-auto`\n - `@shoveller/copy-package`\n - `@orhanemree/create-template`\n - `@perlatsp/devild`\n - `@panfilo/express-template`\n - `typescript-vue-starter`\n - `typescript-express-starter`\n - `@mianfrigo/express-typescript-generator`\n - `@marvinkome/create-node-app`\n - `git-normalize`\n - `env-to-now-json`\n - `guser`\n - `my-chakra-ui`\n - `@dolittle/vanir-common`\n - `menreiki2`\n - `mf-webpack-plugin`\n - `@farazahmad759/dricup-crud-express`\n - `@j.u.p.iter/jupiter-scripts`\n - `crestron-angular-theme`\n - `@benits/teste-ui`\n - `cli-json-edit`\n - `boilerplate-templify-cli`\n - `ecochat-term`\n - `@grogqli/server`\n - `@genesislcap/genx2`\n - `typescript-nest-starter`\n - `typescript-koa-starter`\n - `torder-vue-cli`\n - `@allmywallets/specification`\n - `@jianghe/sand-cli`\n - `@kcom/package-tools`\n - `srf-deploy-qb`\n - `@elastosfoundation/trinity-cli`\n - `term-of-the-day`\n - `simple-webpack-starter`\n - `@spazious/config`\n - `@sapling/cli`\n - `@rajzik/lumos`\n - `@s-ui/changelog`\n - `neu-forge`\n - `malmo`\n - `modern-node-starter`\n - `node-rg`\n - `project-initializer`\n - `@dolittle/webpack`\n - `react-vscode-cli`\n - `react-sgh-scaffolding`\n - `returrn`\n - `@chakra-ui/codemod`\n - `forcemanager-cli`\n - `feeder-cli`\n - `easybackup`\n - `lerna-from-npm`\n - `@crestron/ch5-shell-utilities-cli`\n - `dricup`\n - `h4cksterbot`\n - `gyaon-cli`\n - `def-struct`\n - `iffe-cli`\n - `jad-node-ts-kit`\n - `@triptyk/nfw-cli`\n - `create-cubicus-frontend`\n - `base-express-app-starter`\n - `axereos-hopes`\n - `blip-lang`\n - `create-nuxt-typescript-component`\n - `copancs-microservice-template`\n - `build-swan-plugin`\n - `cucu-generator`\n - `create-cubicus-backend`\n - `create-express-template`\n - `create-express-typescript-application`\n - `@bemedev/publish-command`\n - `dex-cli`\n - `deyarn`\n - `deployqb`\n - `@colorfulcompany/create-cc-jlmf`\n - `fix-package-versions`\n - `express-generator-typescript-k8s`\n - `mongoose-auto-api.cli`\n - `next-nodecms`\n - `kanuki-cli`\n - `sisback`\n - `striplet`\n - `react-easy-boilerplate`\n - `ts-express-starter`\n - `typescript-react-starter`\n - `grafpad`\n - `iffe-commit`\n - `infinitumcli`\n - `@aburkov/scripts`\n - `mtm-cli`\n - `@acanto/workflow`\n - `@deboxsoft/plop-generator`\n - `new-express-app`\n - `jollof-cli`\n - `pandocuments`\n - `lazlodb`\n - `pkgmngrgui`\n - `@hyron/cli`\n - `@anyopsos/cli`\n - `@imklau/react-boilerplate`\n - `@geesmart/zxlib`\n - `@tinyhttp/cli`\n - `@fanxie/cli`\n - `@aquestsrl/create-app-cli`\n - `create-next-library`\n - `ss-clean-slate`\n\n\n\n\n\n\n\n\n\n\n\n## :scroll: License\n\n[MIT][license] © [Ionică Bizău][website]\n\n\n\n\n\n\n[license]: /LICENSE\n[website]: https://ionicabizau.net\n[contributing]: /CONTRIBUTING.md\n[docs]: /DOCUMENTATION.md\n[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg\n[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg\n[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg\n[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg\n[patreon]: https://www.patreon.com/ionicabizau\n[amazon]: http://amzn.eu/hRo9sIZ\n[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=RVXDDLKKLQRJW\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIonicaBizau%2Fedit-json-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIonicaBizau%2Fedit-json-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIonicaBizau%2Fedit-json-file/lists"}