#json-file-plus
A module to read from and write to JSON files, without losing formatting, to minimize diffs.
Example
var jsonFile = require('json-file-plus');
var path = require('path');
var filename = path.join(process.cwd(), 'package.json');
var callback = function (err, result) { };
jsonFile(filename, function (err, file) {
if (err) { return doSomethingWithError(err); }
file.data;
file.format;
file.get('version');
file.get('version', callback);
file.get();
file.get(callback);
file.set({
foo: 'bar',
bar: {
baz: true
}
});
file.remove('description');
file.remove('description', callback);
file.filename = path.join(process.cwd(), 'new-package.json');
file.save(callback).then(function () {
console.log('success!');
}).catch(function (err) {
console.log('error!', err);
});
});
Tests
Simply run npm test
in the repo