bjson
Bind Json: Reactive way to read/write json files.
npm install bjson --save
How it works
When you need to edit a json file, what you do?
- Read json file.
- Deserialize json file.
- Edit parsed object.
- Serialize new object.
- Write back into file.
With bjson:
- Read json file. (Will return parsed object)
- Edit object. (All changes are reactive. Will write it back into file)
Getting started
Binding json
settings.json
whatever.js
var bjson = ;var settings = ; // will read or create settings.jsonsettingsprop = 'bar';
settings.json:
Watching changes with observe
You can watch changes with a instance of Object.observe
passed as callback argument.
settings.json:
whatever.js
var bjson = ;var settings = ; settingsprop = 'foo';settingsotherprop = 'bar';
Log output:
Path: prop
Old Value: bar
New Value: foo
-----
Path: otherprop
Old Value: undefined
New Value: bar
-----
settings.json:
Observe events
var bjson = ;var settings = ;
changes
Observe events callback path
: full path to the property, including nesting
name
: name of the path
type
: name of the event
object
: object
value
: current value for the given path. same as object[name]
oldValue
: previous value of the property
Example:
var bjson = ;var settings = ; settingsfoo = 'bar' //log:// { path: 'foo',// name: 'foo',// type: 'add',// object: { foo: 'bar' },// value: 'bar',// oldValue: undefined }