如何使用jq命令解析其中包含井号#的JSON密钥?

时间:2018-04-04 08:20:09

标签: json jq

我有一个JSON数据:

{
    "module": {
        "data": {
            "deliverySummary_200648721592191#address": {
                "fields": {
                    "address": "MyAddress",
                    "consignee": "MyName",
                    "phone": "MyPhone",
                    "postCode": "",
                    "title": "Alamat Pengiriman \\r\\n"
                },
                "id": "200648721592191#address",
                "tag": "deliverySummary",
                "type": "biz"
            }
        }
    }
}

我想提取这一部分:

{
    "fields": {
        "address": "MyAddress",
        "consignee": "MyName",
        "phone": "MyPhone",
        "postCode": "",
        "title": "Alamat Pengiriman \\r\\n"
    },
    "id": "200648721592191#address",
    "tag": "deliverySummary",
    "type": "biz"
}

我已经尝试了jq '.module.data.deliverySummary_200648721592191#address',但它只返回null而不是我想要的部分,我该如何解决?

1 个答案:

答案 0 :(得分:0)

您应该在问题属性键周围添加双引号,例如'.module.data."deliverySummary_200648721592191#address"'

查看游乐场结果here