merge-json-file
v1.0.1
Published
Merge a JSON file with a JSON object
Downloads
3,419
Maintainers
Readme
Merge a JSON file with a JSON object.
Installation
yarn add merge-json-file
npm install merge-json-file
API
Usage
For existing files:
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:
import { mergeJSON } from "merge-json-file";
mergeJSON("new-file.json", { test: 1 });
// new-file.json:
// {
// "test": 1
// }
//
Types
import { mergeJSON, mergeJSONSync, JSONObject } from "merge-json-file";
function mergeJSON(path: string, object: JSONObject, options?: Options): Promise<boolean>;
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.
Related Packages
- 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