Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amauryd/json-file-rw
https://github.com/amauryd/json-file-rw
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/amauryd/json-file-rw
- Owner: AmauryD
- License: mit
- Created: 2019-08-13T09:11:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-25T14:45:50.000Z (over 5 years ago)
- Last Synced: 2024-12-16T07:55:36.899Z (24 days ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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();
```