json-updater
Nodejs insert to json file
Last updated 11 years ago by archuanickie .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install json-updater 
SYNC missed versions from official npm registry.

json-updater

Inserts new object to your json file without overwriting the content.

why use this?

json-updater doesn't rewrite the whole file but appends the new object to your json file object, which makes it much faster.

installation

npm install --save json-updater

API

insert(filename, obj[,space], callback)

obj object(s) to insert

The optional space argument formats your obj. Default 0 spaces.

Using default space:

var jsonUpdater = require('json-updater');
var file = __dirname + '/users.json';

var obj = {
	"1": {
   	"first_name": "Will",
       "last_name": "Smith"
   }
};

//you can also insert multiple objects
var multiObj = {
	"2": {
   	"first_name": "Google",
       "last_name": "Chrome"
   },
   "3": {
   	"first_name": "Mozilla",
       "last_name": "Firefox"
   },
   "arr": [
     "foo",
     "bar"
   ]
}

jsonUpdater.insert(file, obj, function (err) {
	if(err) return console.error(err);
   //-- your code
});

With space or tab:

jsonUpdater.insert(file, obj, 1, function (err){
	if(err) return console.error(err);
	//-- your code here...
});

jsonUpdater.insert(file, obj, '\t', function (err) {
	if(err) return console.error(err);
    //-- your code here...
});

read(filename[,space], callback)

The callback gets two arguments (err, data) where data is the content of the file

The optional space argument formats the data from callback.

jsonUpdater.read(file, '\t', function (err, data) {
	if(err) return console.log(err);
    console.log(data);
});

Current Tags

  • 1.2.0                                ...           latest (11 years ago)

3 Versions

  • 1.2.0                                ...           11 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 11
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE