Merge a JSON file with a JSON object
npm install merge-json-file> Merge a JSON file with a JSON object.
``sh`
yarn add merge-json-file
`sh`
npm install merge-json-file
#### For existing files:
`ts
import { mergeJSON } from "merge-json-file";
// old-file.json (before):
// {
// "ok": true
// }
//
mergeJSON("old-file.json", { test: 1 });
// old-file.json (after):
// {
// "ok": true,
// "test": 1
// }
//
`
#### For new files:
`ts
import { mergeJSON } from "merge-json-file";
mergeJSON("new-file.json", { test: 1 });
// new-file.json:
// {
// "test": 1
// }
//
`
ts
import { mergeJSON, mergeJSONSync, JSONObject } from "merge-json-file";function mergeJSON(path: string, object: JSONObject, options?: Options): Promise;
function mergeJSONSync(path: string, object: JSONObject, options?: Options): boolean;
type Options = {
/**
* Output formatted JSON. Default:
true
*/
pretty?: boolean;
/**
* Recursively create parent directories if needed. Default: true
*/
recursive?: boolean;
/**
* Ensure file ends with a newline. Default: true
*/
appendNewline?: boolean;
}
``- deepmerge: A library for deep (recursive) merging of Javascript objects
- read-json-safe: Read JSON files without try catch
- write-json-safe: Write formatted JSON to a file
- @bconnorwhite/bob: undefined
- @types/mock-fs: TypeScript definitions for mock-fs
- mock-fs: A configurable mock file system. You know, for testing.
- fs-safe: A simple fs wrapper that doesn't throw
- read-json-safe: Read JSON files without try catch
- write-json-safe: Write formatted JSON to a file