Sala Dus
Sala Dus

Reputation: 45

How to parse this boolean contained JSON output with jq?

The JSON output I am trying to parse:

{
  "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:

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

I would get:

Cannot index boolean with string "aa"

Which makes sense, since the first key is boolean. But I have no clue how to skip it while processing with jq.

Goal is to filter only timestamp and price of "aa", without giving any care about the "success": true key/value pair.

Upvotes: 0

Views: 643

Answers (1)

Jarrod Baker
Jarrod Baker

Reputation: 1220

You need to select the data field first: jq .data.aa[]

Upvotes: 1

Related Questions