Skip to main content

$hasKey

The $hasKey operator checks if an object contains a specific key.

Input

  • An array containing an object/map and a string key name

Output

  • true if the object contains the specified key, false otherwise

Examples

Check If Object Has Key

{
  "$hasKey": [
    {
      "name": "Alice",
      "age": 25,
      "city": "New York"
    },
    "age"
  ]
}
Result: true

Check If Object Does Not Have Key

{
  "$hasKey": [
    {
      "name": "Alice",
      "age": 25,
      "city": "New York"
    },
    "email"
  ]
}
Result: false

From Field

{
  "$hasKey": [
    {
      "$input": "user_object"
    },
    "email"
  ]
}
Result: true if the user_object field contains an “email” key, otherwise false