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

# get_json_string,get_json_object

> Analyzes and gets strings from the specified path (json_path) in a JSON string.

Analyzes and gets strings from the specified path (`json_path`) in a JSON string. If the format of `json_string` or `json_path` is wrong or if no matching value is found, this function will return NULL.

**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)

The alias is get\_json\_object.

## Syntax

```Haskell theme={null}
VARCHAR get_json_string(VARCHAR json_str, VARCHAR json_path)
```

## Parameters

* `json_str`: the JSON string. Supported data type is VARCHAR.
* `json_path`: the JSON path. Supported data type is VARCHAR. `json_path` starts with `$` and uses `.` as the path separator. `[ ]` is used as the array subscripts which starts from 0. For example, `$."my.key"[1]` indicates to obtain the second value form element `my.key`.

## Return value

Returns a value of the VARCHAR type. If no matching object is found, NULL is returned.

## Examples

### Example 1: Get the value whose key is `k1`

```sql theme={null}
SELECT get_json_string('{"k1":"v1", "k2":"v2"}', "$.k1");
```

```sql theme={null}
+---------------------------------------------------+
| get_json_string('{"k1":"v1", "k2":"v2"}', '$.k1') |
+---------------------------------------------------+
| v1                                                |
+---------------------------------------------------+
```

### Example 2: Get the value whose key is `a` from the first element

```sql theme={null}
SELECT get_json_object('[{"a":"123", "b": "456"},{"a":"23", "b": "56"}]', '$[0].a');
```

```sql theme={null}
+------------------------------------------------------------------------------+
| get_json_object('[{"a":"123", "b": "456"},{"a":"23", "b": "56"}]', '$[0].a') |
+------------------------------------------------------------------------------+
| 123                                                                          |
+------------------------------------------------------------------------------+
```

### Example 3: Get the second element in the array whose key is `my.key`

```sql theme={null}
SELECT get_json_string('{"k1":"v1", "my.key":["e1", "e2", "e3"]}', '$."my.key"[1]');
```

```sql theme={null}
+------------------------------------------------------------------------------+
| get_json_string('{"k1":"v1", "my.key":["e1", "e2", "e3"]}', '$."my.key"[1]') |
+------------------------------------------------------------------------------+
| e2                                                                           |
+------------------------------------------------------------------------------+
```

### Example 4: Get the first element in the array whose path is `k1.key -> k2`

```sql theme={null}
SELECT get_json_string('{"k1.key":{"k2":["v1", "v2"]}}', '$."k1.key".k2[0]');
```

```sql theme={null}
+-----------------------------------------------------------------------+
| get_json_string('{"k1.key":{"k2":["v1", "v2"]}}', '$."k1.key".k2[0]') |
+-----------------------------------------------------------------------+
| v1                                                                    |
+-----------------------------------------------------------------------+
```

### Example 5: Get all values whose key is `k1` from the array

```sql theme={null}
SELECT get_json_string('[{"k1":"v1"}, {"k2":"v2"}, {"k1":"v3"}, {"k1":"v4"}]', '$.[*].k1');
```

```sql theme={null}
+-------------------------------------------------------------------------------------+
| get_json_string('[{"k1":"v1"}, {"k2":"v2"}, {"k1":"v3"}, {"k1":"v4"}]', '$.[*].k1') |
+-------------------------------------------------------------------------------------+
| ["v1", "v3", "v4"]                                                                  |
+-------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
```

## keyword

GET\_JSON\_STRING,GET,JSON,STRING


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