> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# json_query

> Queries the value of an element that can be located by the json_path expression in a JSON object and returns a JSON value.

Queries the value of an element that can be located by the `json_path` expression in a JSON object and returns a JSON value.

**Tip**

All of the JSON functions and operators are listed in the navigation and on the [overview page](/documents/4.2/sql-reference/sql-functions/json-functions/overview-of-json-functions-and-operators.md)

Accelerate your queries with [generated columns](/documents/4.2/sql-reference/sql-statements/generated_columns.md)

## Syntax

```Haskell theme={null}
json_query(json_object_expr, json_path)
```

## Parameters

* `json_object_expr`: the expression that represents the JSON object. The object can be a JSON column, or a JSON object that is produced by a JSON constructor function such as PARSE\_JSON.

* `json_path`: the expression that represents the path to an element in the JSON object. The value of this parameter is a string. For information about the JSON path syntax that is supported by the database, see [Overview of JSON functions and operators](/documents/4.2/sql-reference/sql-functions/json-functions/overview-of-json-functions-and-operators.md).

## Return value

Returns a JSON value.

> If the element does not exist, the json\_query function returns an SQL value of `NULL`.

## Examples

Example 1: Query the value of an element that can be located by the `'$.a.b'` expression in the specified JSON object. In this example, the json\_query function returns a JSON value of `1`.

```plaintext theme={null}
mysql> SELECT json_query(PARSE_JSON('{"a": {"b": 1}}'), '$.a.b') ;

       -> 1
```

Example 2: Query the value of an element that can be located by the `'$.a.c'` expression in the specified JSON object. In this example, the element does not exist. Therefore, the json\_query function returns an SQL value of `NULL`.

```plaintext theme={null}
mysql> SELECT json_query(PARSE_JSON('{"a": {"b": 1}}'), '$.a.c') ;

       -> NULL
```

Example 3: Query the value of an element that can be located by the `'$.a[2]'` expression in the specified JSON object. In this example, the JSON object, which is an array named a, contains an element at index 2, and the value of the element is 3. Therefore, the JSON\_QUERY function returns a JSON value of `3`.

```plaintext theme={null}
mysql> SELECT json_query(PARSE_JSON('{"a": [1,2,3]}'), '$.a[2]') ;

       -> 3
```

Example 4: Query an element that can be located by the `'$.a[3]'` expression in the specified JSON object. In this example, the JSON object, which is an array named a, does not contain an element at index 3. Therefore, the json\_query function returns an SQL value of `NULL`.

```plaintext theme={null}
mysql> SELECT json_query(PARSE_JSON('{"a": [1,2,3]}'), '$.a[3]') ;

       -> NULL
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.