使用JQ中的JSON中的两个字段
我想在第二个IP中进行这样的输出:
intranet.site.com:59.89.8.8
尝试运行的命令
cat ./droplet_list.json | jq '.[] | .name , .networks.v4[].ip_address'
运行我正在
"intranet.site.com"
"10.136.95.40"
"59.89.8.8"
"57.23.3.1"
:
cat ./droplet_list.json | jq '.[] | .name , .networks.v4[].ip_address[1]'
并收到错误
“ intranet.site.com” JQ:错误(AT< stdin>:36035):无法用数字索引字符串
我的JSON文件
[
{
"id": 106,
"name": "intranet.site.com",
"networks": {
"v4": [
{
"ip_address": "10.136.95.40",
"netmask": "255.255.0.0",
"gateway": "10.136.0.1"
},
{
"ip_address": "59.89.8.8",
"netmask": "255.255.240.0",
"gateway": "159.0.0.1"
},
{
"ip_address": "57.23.3.1",
"netmask": "255.255.252.0",
"gateway": "157.0.0.1"
}
]
}
}
]
谢谢
I would like to have output like this with second IP:
intranet.site.com : 59.89.8.8
running this command
cat ./droplet_list.json | jq '.[] | .name , .networks.v4[].ip_address'
I have got
"intranet.site.com"
"10.136.95.40"
"59.89.8.8"
"57.23.3.1"
I was trying run:
cat ./droplet_list.json | jq '.[] | .name , .networks.v4[].ip_address[1]'
and got the error
"intranet.site.com" jq: error (at <stdin>:36035): Cannot index string with number
My JSON file
[
{
"id": 106,
"name": "intranet.site.com",
"networks": {
"v4": [
{
"ip_address": "10.136.95.40",
"netmask": "255.255.0.0",
"gateway": "10.136.0.1"
},
{
"ip_address": "59.89.8.8",
"netmask": "255.255.240.0",
"gateway": "159.0.0.1"
},
{
"ip_address": "57.23.3.1",
"netmask": "255.255.252.0",
"gateway": "157.0.0.1"
}
]
}
}
]
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需使用
+
与字符串相连:demo
您也可以给您<<<代码> .v4 数组特定索引(而不是用
[]
在其所有项目上迭代):demo
Just use
+
to concatenate the strings:Demo
You may also give the
.v4
array specific indices (instead of iterating over all of its items with[]
):Demo
一个选项是将
和
以及+
运算符,例如demo
One option would be using
map
along with+
operator such asDemo