awesome-json
v1.2.0
Published
Awesome JSON (plus BSON, YAML, ETF, and MsgPack) writing and reading
Downloads
3
Maintainers
Readme
awesome-json
About
awesome-json is a simple system for reading JSON (plus BSON, YAML, ETF, and MsgPack) files, and automatically writing to the JSON (or BSON/YAML/ETF/MsgPack) file whenever the object is updated. awesome-json supports gzip compression as well.
Installation
npm install --save awesome-json
API
read(filename, [options], callback)
Returns: Promise
options
fs
: any fs module backwards compatible withfs
space
: (JSON only) space argument accepted by JSON.stringifyencoder
: a custom encoder to use while parsing and writing to the fileencoding
: encoding to use while reading the filewriteFrequency
(default: 5000): the length of the interval to write changes in milliseconds, writes immediately if0
Reads a JSON file, and watches for changes. Automatically appends .json
if the file isn't found.
const json = require('awesome-json');
json.read('test', (err, contents) => {
if (err) throw err;
contents.baz = 1; // This change is automatically written to the file.
});
readSync(filename, [options])
Returns: Object
options
fs
: any fs module backwards compatible withfs
space
: (JSON only) space argument accepted by JSON.stringifyencoder
: a custom encoder to use while parsing and writing to the fileencoding
: encoding to use while reading the filewriteFrequency
(default: 5000): the length of the interval to write changes in milliseconds, writes immediately if0
Reads a JSON file, and watches for changes. Automatically appends .json
if the file isn't found.
const json = require('awesome-json');
const contents = json.readSync('test');
contents.baz = 1; // This change is automatically written to the file.