4.0.0 • Published 4 months ago
json-file-plus v4.0.0
json-file-plus 
A module to read from and write to JSON files, without losing formatting, to minimize diffs.
Example
const jsonFile = require('json-file-plus');
const path = require('path');
const filename = path.join(process.cwd(), 'package.json');
jsonFile(filename).then((file) => {
file.data; // Direct access to the data from the file
file.format; // extracted formatting data. change at will.
file.get('version'); // get top-level keys. returns a Promise
file.get(); // get entire data. returns a Promise
/* pass any plain object into "set" to merge in a deep copy */
/* please note: references will be broken. */
/* if a non-plain object is passed, will throw a TypeError. */
file.set({
foo: 'bar',
bar: {
baz: true,
},
});
file.remove('description'); // remove a specific key-value pair. returns a Promise
/* change the filename if desired */
file.filename = path.join(process.cwd(), 'new-package.json');
/* Save the file, preserving formatting. returns a Promise. */
file.save().then(function () {
console.log('success!');
}).catch(function (err) {
console.log('error!', err);
});
});
Tests
Simply run npm test
in the repo
3.3.2
4 months ago
4.0.0
4 months ago
3.3.1
7 years ago
3.3.0
9 years ago
3.2.0
10 years ago
3.1.0
10 years ago
3.0.1
10 years ago
3.0.0
10 years ago
2.0.0
11 years ago
1.0.7
11 years ago
1.0.6
11 years ago
1.0.5
11 years ago
1.0.4
11 years ago
1.0.3
11 years ago
1.0.2
11 years ago
1.0.1
11 years ago
1.0.0
11 years ago
0.2.3
12 years ago
0.2.2
12 years ago
0.2.1
12 years ago
0.2.0
12 years ago
0.1.1
12 years ago
0.1.0
12 years ago
0.0.8
12 years ago
0.0.7
12 years ago
0.0.6
12 years ago
0.0.5
12 years ago
0.0.4
12 years ago
0.0.3
12 years ago
0.0.2
12 years ago
0.0.1
12 years ago