Skip to main content
added relative tag
Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68
Source Link
DonJ
  • 371
  • 2
  • 18

jq filter: show whole structure with selection

I have following file1 json:

{
  "name": "eye",
  "attributes": [
    {
      "name": "Width",
      "value": "1920"
    },
    {
      "name": "Height",
      "value": "1080"
    },
    {
      "name": "WinKeyMapping",
      "value": "leftwin"
    }
  ],
  "starts": [
    {
      "name": "step1",
      "attributeList": [
        {
          "name": "Command",
          "value": "bash"
        },
        {
          "name": "Test",
          "value": "none"
        }
      ]
    }
  ]
}

and following filter:

$ jq '.starts[].attributeList[]|select(.name=="Command")' file1
{
  "name": "Command",
  "value": "bash"
}
$

how could I get whole structure to this selection?

expected output:

{
  "starts": [
    {
      "attributeList": [
        {
          "name": "Command",
          "value": "bash"
        }
      ]
    }
  ]
}