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

# get_json_int

> Extracts an integer value from a JSON string at the specified path.

This function analyzes and gets the integer value from a specified path in json string.

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

json\_path must start with `$` and use `.` as the path separator.

If the path includes `.`, it could be circled by `"` and `"`.

`[ ]` is used as the array subscripts which start from 0.

Content in the path should not contain `"` , `[` and `]`.

If the format of json\_string or json\_path is wrong, this function will return NULL.

## Syntax

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

## Examples

1. Get the value whose key is "k1"

   ```Plain Text theme={null}
   MySQL > SELECT get_json_int('{"k1":1, "k2":"2"}', "$.k1");
   +--------------------------------------------+
   | get_json_int('{"k1":1, "k2":"2"}', '$.k1') |
   +--------------------------------------------+
   |                                          1 |
   +--------------------------------------------+
   ```

2. Get the second element in the array whose key is "my.key"

   ```Plain Text theme={null}
   MySQL > SELECT get_json_int('{"k1":"v1", "my.key":[1, 2, 3]}', '$."my.key"[1]');
   +------------------------------------------------------------------+
   | get_json_int('{"k1":"v1", "my.key":[1, 2, 3]}', '$."my.key"[1]') |
   +------------------------------------------------------------------+
   |                                                                2 |
   +------------------------------------------------------------------+
   ```

3. Get the first element in the array whose path is k1.key -> k2.

   ```Plain Text theme={null}
   MySQL > SELECT get_json_int('{"k1.key":{"k2":[1, 2]}}', '$."k1.key".k2[0]');
   +--------------------------------------------------------------+
   | get_json_int('{"k1.key":{"k2":[1, 2]}}', '$."k1.key".k2[0]') |
   +--------------------------------------------------------------+
   |                                                            1 |
   +--------------------------------------------------------------+
   ```

## keyword

GET\_JSON\_INT,GET,JSON,INT


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