How to Remove Keys from JSON with jq

All jq tools and guides

Use del(.password) to remove a key, or del(.password, .token) to remove several. Specify a nested path to delete a field inside an object, and use map to apply the operation to each array element.

Paste the filter into the playground, or run it in a Unix shell as jq 'FILTER' input.json. Each example below includes its own input and expected output.

Remove one key

Input:

{
  "name": "Ada",
  "password": "example-only",
  "role": "admin"
}

Filter:

del(.password)

Output:

{
  "name": "Ada",
  "role": "admin"
}

Run this example in the jq playground

The filter outputs a new object without the password key. It does not overwrite your input file. Deleting a key that is absent from an object leaves that object unchanged.

Remove multiple keys

Input:

{
  "name": "Ada",
  "password": "example-only",
  "token": "sample-token",
  "role": "admin"
}

Filter:

del(.password, .token)

Output:

{
  "name": "Ada",
  "role": "admin"
}

Run this example in the jq playground

List the paths inside a single del call. The remaining fields retain their values.

Remove a nested key

Input:

{
  "user": {
    "name": "Ada",
    "credentials": {
      "password": "example-only",
      "method": "sso"
    }
  },
  "active": true
}

Filter:

del(.user.credentials.password)

Output:

{
  "user": {
    "name": "Ada",
    "credentials": {
      "method": "sso"
    }
  },
  "active": true
}

Run this example in the jq playground

The path targets only this location. It does not remove other keys named password elsewhere in the document, and it does not automatically remove empty parent objects.

Remove keys from every object in an array

Input:

[
  {
    "name": "Ada",
    "token": "sample-a"
  },
  {
    "name": "Lin",
    "token": "sample-b"
  }
]

Filter:

map(del(.token))

Output:

[
  {
    "name": "Ada"
  },
  {
    "name": "Lin"
  }
]

Run this example in the jq playground

For objects inside an API response, use .users |= map(del(.token)) to retain the surrounding response object. Use .users | map(del(.token)) if you only want the cleaned array.

Remove a key containing dots

Input:

{
  "name": "Ada",
  "debug.enabled": true,
  "debug": {
    "enabled": true
  }
}

Filter:

del(.["debug.enabled"])

Output:

{
  "name": "Ada",
  "debug": {
    "enabled": true
  }
}

Run this example in the jq playground

Bracket notation treats the dot as part of the key. The different expression del(.debug.enabled) removes the nested field instead.

Related guides

Reference: official jq manual.