# BSON\_LENGTH

Returns the number of keys present in the BSON object or array.

## Syntax

```
BSON_LENGTH(<value>)
```

## Argument

`<value>`: A valid BSON object or array, or an expression that evaluates to a valid BSON object or array.

## Return Type

A number.

## Remarks

Returns `NULL` if the input value is one of the following:

* An invalid BSON type
* A BSON type other than a document or an array
* A `NULL`

## Examples

**Note**: The following examples explicitly cast string to BSON for clarity.

```sql
SELECT BSON_LENGTH('{"a":1, "b":2, "c":"abc"}':>BSON) AS Length;

```

```output

+--------+
| Length |
+--------+
|      3 |
+--------+
```

```sql
SELECT BSON_LENGTH('[1, true, null, [7,8,9], "abc"]':>BSON) AS Length;

```

```output

+--------+
| Length |
+--------+
|      5 |
+--------+
```

```sql
SELECT BSON_LENGTH('null':>BSON) AS Length;

```

```output

+--------+
| Length |
+--------+
|   NULL |
+--------+
```

***

Modified at: April 2, 2024

Source: [/db/v9.1/reference/sql-reference/bson-functions/bson-length/](https://docs.singlestore.com/db/v9.1/reference/sql-reference/bson-functions/bson-length/)

(An index of the documentation is available at /llms.txt)
