Reputation: 487
I am having following output after a curl
call
{"snapshotsForStream":[{"id":24221},{"id":24230},{"id":24274}],"code":null,"message":null}
I just want to get the latest snapshot id (24274, in above case) by parsing the output using jq
on windows. What I tried is as follows: -
curl.exe -s --location --request GET "http://myhost:8080/api/v2/streams/stream/snapshots?idType=byName&name=mystream" --header 'Accept:application/json' --user user1:xyz | jq ".snapshotsForStream[-1].id"
It is giving me null.
But when I ran same command on a linux machine then it is giving me the correct output as 24274
So just want to know that whether there is any way to get the last entry of an array through jq
json parsing.
Upvotes: 1
Views: 281
Reputation: 85800
Accessing elements with negative indices was introduced in jq-1.5
, you seem to be running a version before that which is really old. See -1 index doesn't work #1388
Consider upgrading to jq-1.6
the most recent version released. See jq - Releases
Upvotes: 2