Skip to main content
Checks whether a JSON document contains a specific value or subdocument. If the target JSON document contains the candidate JSON value, the JSON_CONTAINS function returns 1. Otherwise, the JSON_CONTAINS function returns 0. Tip All of the JSON functions and operators are listed in the navigation and on the overview page

Syntax

Parameters

  • json_target: the expression that represents the target JSON document. The document can be a JSON column, or a JSON object that is produced by a JSON constructor function such as PARSE_JSON.
  • json_candidate: the expression that represents the candidate JSON value or subdocument to search for within the target. The value can be a JSON column, or a JSON object that is produced by a JSON constructor function such as PARSE_JSON.

Return value

Returns a BOOLEAN value.

Usage notes

  • For scalar values (strings, numbers, booleans, null), the function returns true if the values are equal.
  • For JSON objects, the function returns true if the target object contains all key-value pairs from the candidate object.
  • For JSON arrays, the function returns true if the target array contains all elements from the candidate array, or if the candidate is a single value contained in the target array.
  • The function performs deep containment checking for nested structures.

Examples

Example 1: Check if a JSON object contains a specific key-value pair.
Example 2: Check if a JSON object contains a key-value pair that doesn’t exist.
Example 3: Check if a JSON array contains specific elements.
Example 4: Check if a JSON array contains a single scalar value.
Example 5: Check if a JSON array contains elements that don’t exist.
Example 6: Check containment with nested JSON structures.
Note: In the last example, the result is 0 because array containment requires exact element matching, not partial object matching within arrays.