Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 706 Bytes

README.md

File metadata and controls

35 lines (28 loc) · 706 Bytes

JSONFile

Asynchronous Node.js JSON file reader, writer, and modifier.

Usage

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());