用JQ解析JS,负索引无法在Windows上工作

发布于 2025-02-11 12:16:14 字数 611 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执妄 2025-02-18 12:16:15

访问元素带负索引 是在>中引入的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 #1388

Consider upgrading to jq-1.6 the most recent version released. See jq - Releases

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文