jq - 如果值不为null,如何输出文档?

时间:2018-03-05 08:04:27

标签: json jq

如果finalStatus!= null,我试图找到如何从以下数组中提取文档的方法。

我试过select(.[].finalStatus != null)但没有成功。我仍然得到两条线。

[
  {
    "_type": "http",
    "uri": "/rest/eFulfillment/V1/stock/5117855/OHK30",
    "status": 200,
    "statustext": "OK",
    "method": "GET",
    "vhost": null,
    "wafStatus": 0,
    "bytesSent": 0,
    "bytesReceived": 0,
    "remoteName": "connecte-esb-bat.dhl.com",
    "remoteAddr": "165.72.94.127",
    "localAddr": "165.72.1.236",
    "remotePort": "443",
    "localPort": "52842",
    "sslsubject": "/C=DE/ST=Nordrhein-Westfalen/L=Bonn/O=Deutsche Post AG/OU=ITSC/CN=connecte-esb-bat.dhl.com",
    "leg": 1,
    "timestamp": 1520235200649,
    "duration": 1099,
    "correlationId": "c0f29c5a3e484ba5419878db",
    "serviceName": "PeP e-Fulfillment API",
    "subject": "d006366e-3b9e-415f-baff-cc1eec24898a",
    "operation": "Get Available Stock",
    "type": "http",
    "finalStatus": null
  },
  {
    "_type": "http",
    "uri": "/efulfillment/v1/stock/5117855/OHK30",
    "status": 200,
    "statustext": "OK",
    "method": "GET",
    "vhost": null,
    "wafStatus": 0,
    "bytesSent": 0,
    "bytesReceived": 0,
    "remoteName": "165.72.87.12",
    "remoteAddr": "165.72.87.12",
    "localAddr": "165.72.1.236",
    "remotePort": "51946",
    "localPort": "6443",
    "sslsubject": null,
    "leg": 0,
    "timestamp": 1520235200642,
    "duration": 1107,
    "correlationId": "c0f29c5a3e484ba5419878db",
    "serviceName": "PeP e-Fulfillment API",
    "subject": "d006366e-3b9e-415f-baff-cc1eec24898a",
    "operation": "Get Available Stock",
    "type": "http",
    "finalStatus": "Pass"
  }
]

我在这里搜索了其他文章,但即使我发现它对我来说也没用。

1 个答案:

答案 0 :(得分:2)

尝试map(select(.finalStatus != null))

https://jqplay.org/s/CzPU5im0RE