support for json_decode and json_encode
coderofsalvation opened this issue · 0 comments
coderofsalvation commented
make jq-dependency for json integration:
powscript:
cat foo.json | json_decode items.users
if not value =~
echo "$keys"
echo "$values"
echo "$id $name $email"
bash:
cat foo.json | json_decode items.users # this will output tsv: "12\t'foo'"
| json_expose
local keys="${*//[a-zA-Z0-9_]:/}"
local values="${*//:['"a-zA-Z0-9_]\t/\t}"
local id=12
local name="foo"
echo "$*" | grep "id:12" | awk '{print $2}' # will output name:'foo'
echo
done
why jq
first I thought about a fallback-mechanism to:
node -pe 'JSON.parse(process.argv[1]).foo' "$(cat foobar.json)"
python curl -s http://twitter.com/users/username.json | python -c "import json,sys;obj=json.load(sys.stdin);print obj['name'];"
perl
jq
why not json.sh or json.awk
- json.sh: probably slow and could break whole application.
- json.awk that would be better if it would evaluate simple 'jsonpaths' (can it?)
however, that introduces many incompatibilities concerning the jsonpath syntax-dialects.
JQ however:
- is already in many package-repositories
- could eventually easily become optional dependency of bash (native binding etc)
- is lightweight/fast/portable dependency (compared to node/python/perl)
- does support basic jsonpath evaluation