jq not showing all the results

I have the following json:

[
  {
    "_source": {
      "layers": {
        "http2": {
          "http2.stream": {
            "http2.length": "1030"
          }
        },
        "http2": {
          "http2.stream": {
            "http2.length": "1246"
          }
        }
      }
    }
  }
]

I am doing the following jq command:

jq '.[]._source.layers.http2."http2.stream"' file.json

I am expecting to get the following result:

{
  "http2.length": "1030"
}
{
  "http2.length": "1246"
}

But I am only getting:

{
  "http2.length": "1246"
}
Asked By: Manuel Rijo

||

Jq behaves as reasonably as possible here, expecting JSON as input. JSON dictionaries are unique key-value mappings, and your key"http2" appears twice.

So, you’re requesting a lookup on a duplicate key, and that successfully gets you the last value specified for it, tolerating invalid input as well as possible.

Answered By: Marcus Müller
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.