Extract `key` and `value`.

TODO: collapasable, copyable, download, etc

I have JSON coming back like { "metricName": "duration", "metricUnit": "ms", "times": [ "1700009150", "1700009165", "1700009180", "1700009215", "1700009230", "1700009245", "1700009260", "1700009275", "1700009290", "1700009305", "1700009320", "1700009335", "1700009350", "1700009365", "1700009380", "1700009395", "1700009410", "1700009425", "1700009440", "1700009455", "1700009470", "1700009485" ], "data": [ { "header": [ { "key": "attributes:span.name", "operator": "=", "value": "CurrencyService/Convert" }, { "key": "attributes:flag.productCatalogTimeout", "operator": "=", "value": "" } ], "aggregator": "AVG", "seriesTitle": "AVG(duration), span.name = CurrencyService/Convert, flag.productCatalogTimeout = ", "values": [ { "isNull": true }, { "value": 0.0562166 }...

I want to just show data.header.key and data.header.value. What is the jq syntax to pipe the output through?To extract the key and value fields from the header array inside the data object using jq, you can use the following command:

jq '.data[].header[] | {key, value}'

This command does the following:

  • .data[]: Iterates over each element in the data array.
  • .header[]: For each element in data, iterates over each element in the header array.
  • {key, value}: Creates a new object for each element in header, containing only the key and value fields.

This will output each key and value pair in the header array of each object in the data array.

Extract `key` and `value`. created at Tue Jan 20 1970 18:02:32 GMT+0000 (Coordinated Universal Time)

Related Chats

Learn `jq` Basics 0.424

Base64 encoded values. 0.396

Python Server Streaming JSON 0.395

SF Fine Dining Recommendations 0.386

Aggregate Highcharts data in 5-min. 0.338

New chat 0.328

Streaming JSON Parsing Issue 0.322

Luxon for Human-Friendly Durations 0.302

Remove leading spaces. 0.302