awesome-json

1.2.0 • Public • Published

awesome-json

Build Status dependencies Status optionalDependencies Status

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 with fs
  • space: (JSON only) space argument accepted by JSON.stringify
  • encoder: a custom encoder to use while parsing and writing to the file
  • encoding: encoding to use while reading the file
  • writeFrequency (default: 5000): the length of the interval to write changes in milliseconds, writes immediately if 0

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 with fs
  • space: (JSON only) space argument accepted by JSON.stringify
  • encoder: a custom encoder to use while parsing and writing to the file
  • encoding: encoding to use while reading the file
  • writeFrequency (default: 5000): the length of the interval to write changes in milliseconds, writes immediately if 0

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.

Package Sidebar

Install

npm i awesome-json

Weekly Downloads

1

Version

1.2.0

License

MIT

Last publish

Collaborators

  • hackzzila