json-file-rw
v0.0.5
Published
Json file writer and reader
Downloads
6
Readme
json-file-rw
Read and write to json file
Install
npm install json-file-rw
Test
mocha
Example
// sync example
const jsonFileWriter = require('json-file-rw');
const fileWriter = new jsonFileWriter({
spacing : 2,
replacing : null
});
fileWriter.openSync('file.json');
fileWriter.setNodeValue("test",123);
fileWriter.setNodeValue("hello.deep.value","Hey , i'm so deep");
const value = fileWriter.getNodeValue("hello.deep.value");
console.log(value);
const iDoNotExists = fileWriter.getNodeValue("hello.deep.foo","oops");
console.log(iDoNotExists);
fileWriter.saveSync();
//async example
const jsonFileWriter = require('json-file-rw');
const fileWriter = new jsonFileWriter();
await fileWriter.open('file.json');
fileWriter.setNodeValue("test",123);
fileWriter.setNodeValue("hello.deep.value","Hey , i'm so deep");
const value = fileWriter.getNodeValue("hello.deep.value");
console.log(value);
const iDoNotExists = fileWriter.getNodeValue("hello.deep.foo","oops");
console.log(iDoNotExists);
await fileWriter.save();