https://github.com/tiaanduplessis/json-reader-writer
Read or write to a JSON file synchronously
https://github.com/tiaanduplessis/json-reader-writer
json json-reader-writer
Last synced: 11 months ago
JSON representation
Read or write to a JSON file synchronously
- Host: GitHub
- URL: https://github.com/tiaanduplessis/json-reader-writer
- Owner: tiaanduplessis
- License: mit
- Created: 2017-01-29T18:05:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-23T18:15:29.000Z (over 6 years ago)
- Last Synced: 2025-07-21T16:20:11.867Z (11 months ago)
- Topics: json, json-reader-writer
- Language: JavaScript
- Homepage:
- Size: 51.8 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
📘 json-reader-writer ✍️
Read or write to a JSON file synchronously
Table of Contents
Table of Contents
## Install
Note that this module Uses JSON.stringify, which can [run out of memory](https://github.com/nodejs/node/issues/13465). If the data you need to write is large, consider using a streaming JSON writer, such as @mbostock's [json-write](https://www.npmjs.com/package/json-write). Otherwise, go ahead and...
```sh
$ npm install --save json-reader-writer
```
```sh
$ yarn add json-reader-writer
```
## Usage
```js
const {readJSON, writeJson} = require('json-reader-writer')
const filePath = 'foo.json'
const obj = {
foo: 1,
bar: 2,
baz: 2
}
console.log(writeJson(filePath, obj)) // true if successful
console.log(readJSON(filePath)) // { foo: 1, bar: 2, baz: 2 }
```
## API
### readJSON(filename)
Takes the filename of the JSON file you want to read from as argument. Defaults to `file.json` if no `filename` provided.
### writeJSON(filename, objectToWrite)
Takes the filename of the JSON file you want to write to and the valid object you want to write as arguments.
## Contribute
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
Licensed under the MIT License.