Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mlconnor
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlconnor/a87ca81b0ca0c7493588 to your computer and use it in GitHub Desktop.
Save mlconnor/a87ca81b0ca0c7493588 to your computer and use it in GitHub Desktop.
Concept for allowing JSON to inherit from other defs
var fs = require('fs');
var _ = require('lodash');
var defs = fs.readFileSync('servicedefs.json', {encoding:'utf8'});
var defsJson = JSON.parse(defs);
var indexedDefs = _.indexBy(defsJson, 'id');
_.each(indexedDefs, function(def, index) {
var current = def;
while ( _.has(def, 'under') ) {
var ref = indexedDefs[def.under];
if ( ! ref ) {
throw "could not resolve under [" + def.under + "]";
}
delete def.under;
var underClone = _.clone(ref);
_.merge(underClone, def);
current = underClone;
}
indexedDefs[index] = current;
});
console.log(JSON.stringify(indexedDefs,null,' '));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment