curl 'url' | jq '.[0]'
https://pastebin.com/5i5VDBYz
returns
jq: error (at <stdin>:0): Cannot index object with number
on Linux box.example.com 4.14.17-x86_64 (Ubuntu 16.04)
The JSON at https://pastebin.com/5i5VDBYz is an object, and as the error message says, you "cannot index [an] object with [a] number". Since you haven't indicated what you are trying to do, it's hard to know what you intended, but you might like to lookup .[] in the jq manual.
For future reference, please ask usage questions at stackoverflow.com using the jq tag. See also the "minimal complete verifiable example" guidelines at http://stackoverflow.com/help/mcve
thx. i am trying to extract a single element from the JSON.
Here is one approach for anyone finding this on their search for an answer:
echo '[{"name":"joe"}, {"name":"john"}, {"name":"jose"}]' | jq '[.[] | .name] | .[1]'
This will wrap the processed data in an array from which you can index a particular value.
Here is one approach for anyone finding this on their search for an answer:
echo '[{"name":"joe"}, {"name":"john"}, {"name":"jose"}]' | jq '[.[] | .name] | .[1]'
This will wrap the processed data in an array from which you can index a particular value.
Thank you so much @rbrisita
echo '[{"name":"joe"}, {"name":"john"}, {"name":"jose"}]' | jq '[.[] ] | .[0]'
will bring back the first element of any json doc AFAIK
Most helpful comment
Here is one approach for anyone finding this on their search for an answer:
echo '[{"name":"joe"}, {"name":"john"}, {"name":"jose"}]' | jq '[.[] | .name] | .[1]'
This will wrap the processed data in an array from which you can index a particular value.