node-json-file

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i node-json-file

Weekly Downloads

0

Version

1.1.0

License

MIT

Last publish

Collaborators

  • fuhuixiang