Skip to content

Instantly share code, notes, and snippets.

@lukekarrys
Created July 30, 2012 23:08
Show Gist options
  • Save lukekarrys/3211699 to your computer and use it in GitHub Desktop.
Save lukekarrys/3211699 to your computer and use it in GitHub Desktop.
Quick Node script to merge to extend one JSON file with another and save it
/*global require console */
var _ = require('underscore'),
fs = require('fs'),
data = JSON.parse(fs.readFileSync('./data.json', 'utf-8')).data;
_.each(data, function(item) {
var newJson = item[0],
files = item[1];
_.each(files, function(file) {
var path = '.' + file,
oldJson = JSON.parse(fs.readFileSync(path, 'utf-8')),
newJson = _.extend(oldJson, newJson),
printableJson = JSON.stringify(newJson, null, 2);
fs.writeFile(path, printableJson, function(err) {
if (err) throw('File save error: '+ err);
console.log('file saved');
});
});
});
@ecdeveloper
Copy link

What about big json files (which exceed the limit of 512/1024 mb)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment