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

# JSON_ARRAY_LENGTH

## Overview

The `JSON_ARRAY_LENGTH()` function returns the length of a specified JSON array.

## Syntax

This function has the following basic syntax.

```sql theme={null}
JSON_ARRAY_LENGTH(arrayval JSON)
```

The required argument for this function is `arrayval`. It represents the JSON array which we will count the length.

## Examples

### Case #1: Get a JSON array length with a JSON value

The following example returns the number of elements in the array:

```sql theme={null}
SELECT JSON_ARRAY_LENGTH('[4, 7, 10, 11, 14, {"vegetables":"spinach","fruits":"melon"}, {"a":"b"}]');
```

The function above will return the following result:

```sql theme={null}
+-------+
| f     |
+-------+
| 7     |
+-------+
```

### Case #2: Get a JSON array length with a number

The following example returns the number of elements in the array.

```sql theme={null}
SELECT JSON_ARRAY_LENGTH('[1, 2, [3, 4]]');
```

You will get the final result as follows:

```sql theme={null}
+-------+
| f     |
+-------+
| 3     |
+-------+
```

### Case #3: JSON array length where the array is NULL or empty

This example shows that an empty JSON array will return 0.

```sql theme={null}
SELECT JSON_ARRAY_LENGTH('[]');
```

An empty array will return 0 in the final output:

```sql theme={null}
+-------+
| f     |
+-------+
| 0     |
+-------+
```
