easyjson
Tiny node.js module to manipulate JSON file with add/delete/modify/get json data easily. Also support nested datas.
Installation
$ npm install easyjson
Or
$ component install Tinple/easyjson
EasyJSON
With EasyJSON
you can simply invoke the exported function to manipulate JSON file.
At first, passing a path to path
function to choose a JSON file. And EasyJSON
support the chain call.
Example app.js:
var easyjson = ; // it should output your JSON fileeasyjson ;
You can also add, modify or delete a item with your JSON file. And EasyJSON
support chained invoke.
var easyjson = ; easyjson ;
easyjson
can get the value of your item with JSON file. Just call get(key)
to get it.
var easyjson = author = easyjson email = easyjson;
Most Useful(support nested data)
Actually, EasyJSON
support nested data, that means you
can manipulate your JSON file most effectivly.
var easyjson = ; /** * "author": { * "name": "Tinple" * } * ==> * "author": { * "name": "Tinple", * "friend": { * "name": "Kristine" * } * } */easyjson; /** * push 'path.json' to existed array files * "files": ["index.js"] * ==> * "files": ["index.js", "path.json"] */easyjson; // it will delete whole friend object, the same as arrayeasyjson; // modify the array, only index supporteasyjson; // modify the obj keyeasyjson; /** More complex * "author": { * "name": "Tinple" * } * ==> * "author": { * "name": "Tinple", * "friend": [{ * "name": "Kristine" * }] * } */easyjson;
Warning
EasyJSON
will do nothing when you pass a nonexistent
key to modify()
and del()
. As for add(key, value)
, EasyJSON
will judge whether the key exists firstly. If not, it will added normally.
If it has already existed, there are two situations that the key should be treated.
- The key is an array, then the value will be pushed.
- The key is other type, like Object or String, then
EasyJSON
do nothing.
License
MIT