Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/amauryd/json-file-rw


https://github.com/amauryd/json-file-rw

Last synced: 22 days ago
JSON representation

Awesome Lists containing this project

README

        

# json-file-rw

Read and write to json file

## Install
```bash
npm install json-file-rw
```

## Test
```bash
mocha
```

## Example

```js
// 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();
```

```js
//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();
```