用JQ解析JS,负索引无法在Windows上工作
在curl
调用之后,我正在以下输出,
{"snapshotsForStream":[{"id":24221},{"id":24230},{"id":24274}],"code":null,"message":null}
我只想通过使用Windows上的JQ
来获得输出,以获取最新的快照ID(24274,在上述情况下为24274)。我尝试的内容如下: -
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"
它使我无效。 但是,当我在Linux计算机上运行同一命令时,它将为我提供正确的输出,作为24274
,
因此只想知道是否有任何方法可以通过获得数组的最后一个条目JQ
JSON解析。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
访问元素带负索引 是在
>中引入的JQ-1.5
,您似乎正在运行一个真正旧的版本。参见 - 1个索引不起作用#1388考虑升级到
jq-- jq-- 1.6
发布的最新版本。参见 jq-释放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 #1388Consider upgrading to
jq-1.6
the most recent version released. See jq - Releases