json - jq sorts KEY and VALUES in different way - how can I enumerate them in the same order? -
i rest output in json format using curl command below
getting key names alone using:
curl http://test.te:8080/testapp/app/version | jq '.version' | jq '. | keys' output:
"archiver-version", "build-id", "build-jdk", "build-number", "build-tag", "built-by" getting values alone using:
curl http://test.te.com:8080/testapp/app/version | jq '.version' | jq '.[]' output (note how order of values doesn't correspond order of key names; e.g., first value, "user@test.com", value key "built-by", not, expect, first key, "archiver-version"):
"user@test.com" "1634d38" "sandbox" "02-03-2014-13:41" "testapp" i trying assign keys , values separate arrays, can iterate on them , display them in table format.
but these 2 commands sorted in different way, cannot assign values , keys directly.
is there anyway change sorting of keys , values both same?
jq has option sort keys. see http://stedolan.github.io/jq/manual/#invokingjq
--sort-keys / -s: output fields of each object keys in sorted order. however current released version (1.3) of jq doesn't have enhancement yet, you'll need compile jq via latest code it's master branch. see http://stedolan.github.io/jq/download/ , "from source on linux or os x" section.
for complete history , details of feature, see issue #79 "option or function sort object members name" https://github.com/stedolan/jq/issues/79
Comments
Post a Comment