- You need to append to a json file, but sometimes it hasn't been created yet.
- This solves that problem.
var myJson = {
name: {
first: 'Jackson',
last: 'Geller'
}
}
// My file contains {dob: '9/27/1994'}
var myFile = 'data.json'
// Call -- creates file if it doesn't exist and appends
appendjson(myJson, myFile, function() {
console.log('done')
})
/* output -- data.json
{
dob: '9/27/1994,
name: {
first: 'Jackson',
last: 'Geller'
}
}
*/
npm install appendjson --save
var appendjson = require('appendjson');
appendjson(jsonObj, filepath, callback)