简体   繁体   English

如何使用 jq 解析包含这个布尔值的 JSON 输出?

[英]How to parse this boolean contained JSON output with jq?

The JSON output I am trying to parse:我试图解析的 JSON 输出:

{
  "success": true,
  "data": {
    "aa": [
      {
        "timestamp": 123456,
        "price": 1
      },
      {
        "timestamp": 123457,
        "price": 2
    ],
    "bb": [
      {
        "timestamp": 123456,
        "price": 3
      },
      {
        "timestamp": 123457,
        "price": 4
      }
    ]
  }
}

So after banging my head against the wall a million times, I just removed the "success": true", line from the output and I could easily do jq stuff with it. Otherwise if I ran for example:因此,在我的头撞墙一百万次之后,我只是从输出中删除了"success": true",行,我可以很容易地用它做 jq 的东西。否则,如果我运行,例如:

cat jsonfile.json | jq -c .[].aa

I would get:我会得到:

Cannot index boolean with string "aa"无法用字符串“aa”索引布尔值

Which makes sense, since the first key is boolean.这是有道理的,因为第一个键是布尔值。 But I have no clue how to skip it while processing with jq.但我不知道如何在使用 jq 处理时跳过它。

Goal is to filter only timestamp and price of "aa", without giving any care about the "success": true key/value pair.目标是只过滤“aa”的时间戳和价格,而不关心“成功”:真正的键/值对。

需要先选择data字段: jq .data.aa[]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM