本文介绍了密钥中有空格时的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真让我发疯.

我有一个看起来像这样的JSON:

I have a JSON that looks like this:

{
"gateways": [
    {
        "DHCP": "On",
        "External IPs": "46.244.46.66",
        "Firewall": "On",
        "NAT": "Off",
        "Name": "gateway",
        "Routed Networks": "photon, default-routed-network",
        "Selected": "*",
        "Syslog": "",
        "Uplinks": "d5p6v51-ext",
        "VPN": "Off"
    }
]
}

我可以轻松提取大多数键的值.

I can easily extract values for most of the keys.

例如

jq --raw-output .gateways[0].Name
gateway

但是,我真正需要得到的是"External IPs"值,我不知道如何管理空间.

However, what I really need to get is the "External IPs" value and I can't figure out how to manage the space.

我尝试过

jq --raw-output .gateways[0].'External IPs'

jq --raw-output .gateways[0].`External IPs`

jq --raw-output .gateways[0]."External IPs"

但是这些都不起作用.

But none of these work.

有任何提示吗?

推荐答案

使用引号如下:

jq --raw-output '.gateways[0]."External IPs"'

这篇关于密钥中有空格时的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 07:45