I have some JSON but I want to extract data based on a variable using jq

Solution 1:

Assuming those input objects are in an array,

.[] | select(.metadata.name == "run2") | .metadata

Will select the object where .metadata.name === run2.

Then it shows the .metadata of that object so the output becomes:

{
  "name": "run2",
  "uid": "9b0af3",
  "creationTimestamp": "2021-01-01T01:01:01Z"
}

Demo