jq-将值插入子项

时间:2019-06-09 07:38:04

标签: json jq

我有一个httpie会话文件,如下所示:

{
   "headers": {
      "Host": "34.213.0.202",
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
      "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0",
      "Accept-Language": "en-US,en;q=0.5",
      "Accept-Encoding": "gzip, deflate",
      "DNT": "1",
      "Connection": "keep-alive",
      "Upgrade-Insecure-Requests": "1",
      "Cache-Control": "max-age=0"
    }
}

我想将项目插入标头(请考虑'。headers + {“ Cookie”:“ xyz”}'),但我希望输出为整个JSON。使用jq'.headers + {“ Cookie”:“ xyz”}'仅打印出.headers值。我想要获取的是整个JSON,但其中包含cookie子项。

那是什么方法?

1 个答案:

答案 0 :(得分:1)

使用赋值运算符:

.headers += { Cookie: "xyz" }
.headers.Cookie = "xyz"

当要添加多个字段时,后一个会有所变化:

.headers |= (.Cookies = "xyz" | .Referer = "xyz")