json-update

Allows for very simple JSON file updating in one line

This is a simple way to update (or load) a JSON file. If the JSON file does not exist it will be created (along with a directory structure if those directories don't exist yet).

Uses underscore to extend existing JSON data with the object you specify, overriding anything with an existing property and adding properties if they are new.

npm install json-update

Updating a JSON file (and return the new object):

json = require('json-update')
 
json.update('data.json', { test: 'value x' }, function(errobj) {
  if (typeof err !== "" && err !== null) {
    console.log("Error updating json: " + err.message);
  }
  console.log(obj);
});

Loading a JSON file (note that in the case of loading a valid JSON file must already exist):

json = require('json-update')
 
json.load('data.json', function(errobj) {
  console.log("Loaded from json:");
  console.log(obj);
});