1.1.0 • Published 7 years ago

node-json-file v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

node-json-file

Build Status npm npm npm

This is node runtime json file tool.

install:

npm install --save node-json-file

select attribute

const jsonTool = require('node-json-file');

let jsonTest = jsonTool(`${__dirname}/test.json`);

jsonTest.select('name');

// 查找全部属性
jsonTest.select();

update attribute

Updated after the json object does not really save the original file, need to invoke the sava method to save() another.

const jsonTool = require('node-json-file');

let jsonTest = jsonTool(`${__dirname}/test.json`);

jsonTest.update({a: 'b'});

// update one attr
jsonTest.update('a', false);

delete attribute

const jsonTool = require('node-json-file');

let jsonTest = jsonTool(`${__dirname}/test.json`);

jsonTest.del('a');

get all attribute number

const jsonTool = require('node-json-file');

let jsonTest = jsonTool(`${__dirname}/test.json`);

jsonTest.count();

save json object

const jsonTool = require('node-json-file');

let jsonTest = jsonTool(`${__dirname}/test.json`);

jsonTest.save(`${__dirname}/test2.json`);

// save original file
jsonTest.save();

find json object

const jsonTool = require('node-json-file');

let jsonTest = jsonTool(`${__dirname}/test.json`);

jsonTest.find('test1');
// if not find key, return undefined