Asynchronous Node.js JSON file reader, writer, and modifier.
Initialize:
const jsonFile = await new JSONFile(filePath, initialData);
Read:
const data = await jsonFile.read();
Write:
await jsonFile.write({foo: 'bar'});
Modify:
await jsonFile.modify({foo: 'car'});
Example:
const jsonFile = await new JSONFile('./Data.json', {
"name": "John",
"age": 35,
"email": "[email protected]",
"phone": "+1-123-456-7890",
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
}
});
await jsonFile.modify({name: "Alex", available: true});
console.log(await jsonFile.read());