Created
June 10, 2017 18:17
-
-
Save codecontemplator/0674d6f9af3a27308fda685f53031a32 to your computer and use it in GitHub Desktop.
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
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