Nic
Nic

Reputation: 461

JQ: exclude specified embedded keys

From the following input:

{
    "key1": {
        "key_x": "1",
        ...
        "key_z": "2"
    },
    "key2": {
        "key_x": "2",
        ...
        "key_z": "3"
    }
}

I would like to exclude all keys with the name "key_x" so the result should be

{
    "key1": {
        ...
        "key_z": "2"
    },
    "key2": {
        ...
        "key_z": "3"
    }
}

Upvotes: 27

Views: 14784

Answers (1)

hek2mgl
hek2mgl

Reputation: 158170

You can use the del() function:

jq 'del(.[]|.key_x)' input.json

Upvotes: 32

Related Questions