Skip to content

Instantly share code, notes, and snippets.

@codecontemplator
Created June 10, 2017 18:17
Show Gist options
  • Save codecontemplator/0674d6f9af3a27308fda685f53031a32 to your computer and use it in GitHub Desktop.
Save codecontemplator/0674d6f9af3a27308fda685f53031a32 to your computer and use it in GitHub Desktop.
var JSONPath = require('JSONPath');
const doc = require('./mapping.json');
const mappings = JSONPath({json: doc, path: "$['serilog-2017.05'].mappings.*", resultType: "all" });
function countProps(obj) {
var result = 0;
if (obj) {
Object.getOwnPropertyNames(obj).forEach(function(p) {
result += 1 + countProps(obj[p].properties);
});
}
return result;
}
var result = mappings.map(function(mapping) {
return {name:mapping.parentProperty, count:countProps(mapping.value.properties)};
});
result.sort(function(a,b) {
return b.count - a.count;
});
console.log(JSON.stringify(result, null, 4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment