Created
July 30, 2012 23:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about big json files (which exceed the limit of 512/1024 mb)?