Jq 根据curl请求失败的成功与否选择不同的密钥
我从curl请求中得到了以下输出,根据请求的成功/失败,这些输出可能会有所不同 成功:Jq 根据curl请求失败的成功与否选择不同的密钥,jq,Jq,我从curl请求中得到了以下输出,根据请求的成功/失败,这些输出可能会有所不同 成功: { "name": "appId (xxxxx-xxx-1234)", "sent": 7939246, "received": 6673490, "details": [ { "timestamp": "20180201000041", "sentbytes": 1805, "receivedbytes": 1485 } ]} 失败: {
{
"name": "appId (xxxxx-xxx-1234)",
"sent": 7939246,
"received": 6673490,
"details": [
{
"timestamp": "20180201000041",
"sentbytes": 1805,
"receivedbytes": 1485
}
]}
失败:
{
"error": "Not found"
}
有人能告诉我如何检查是否存在发送或错误。我试过了
jq '. | select (.error | .sent)
但这似乎不是正确的语法。你很接近
jq '. | select(.error or .sent)'
甚至更短,不需要额外的管道:
jq '.sent or .error'
输出:
true
虽然我使用jq-r'select.error或.sent',但我得到的输出是{error:Not Found}有没有一种方法可以只得到我在使用jq-r.error'时得到的原始输出,因为我想得到进一步处理的值