Created
April 11, 2017 09:17
-
-
Save chernjie/0408605d8a39cea56fccd4f9099f4ba5 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
#!/usr/bin/env bash | |
json2markdowntable () { | |
local headers=$@ | |
echo $headers | sed "s, , | ,g" | |
seq $# | while read i; do echo " --- "; done | xargs | sed "s, , | ,g" | |
json -a $headers -d" | " | |
} | |
# json2markdowntable $@ | |
filterByKeys() { | |
local headersjs="$(echo $@ | xargs -n1 | sed -e s,^,+, -e s.$.+,. | xargs | sed -e s,+,"'",g -e s,^,"[", -e s,$,"]",)" | |
json -ga -E " | |
var headersjs = $headersjs; | |
var that = this; | |
Object.keys(that).forEach(function(el){ | |
if (that[el] !== null && typeof that[el] === 'object') { | |
Object.keys(that[el]).forEach(function(ell){ | |
var key = [el, ell].join('.'); | |
that[key] = that[el][ell]; | |
delete that[el][ell]; | |
}) | |
} | |
if (headersjs.indexOf(el) === -1) { | |
delete that[el]; | |
} | |
}) | |
" | json -g | |
} | |
filterByKeys $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment