json-helper-toolkit
v1.1.7
Published
Toolkit for easier JSON manipulation.
Downloads
5
Readme
json-helper-toolkit
Toolkit for easier JSON manipulation.
Code Examples
/test.json
{
"name": "test-name"
}
/src/index.ts
import { modifyJson, readJson } from "json-helper-toolkit";
// ------
interface Test {
name: string;
changed?: boolean;
}
// Argument path should be based on the current work directory.
// You can check the directory with "process.cwd()".
const [, data] = readJson<Test>("test.json");
console.log(data.name); // "test-name"
data.name = "changed-name";
data.changed = true;
modifyJson("test.json", data);
// ------
const [modifiedPath, modifiedData] = readJson<Test>("test.json");
console.log(`Checking "${modifiedPath}"`);
if (modifiedData) {
// Console : changed-name
console.log(modifiedData.name);
// Console : true
console.log(modifiedData.changed);
}