# BSON\_EXTRACT\_BOOL

Extracts the boolean value for the specified key from the BSON data, converts it to the SingleStore `TINYINT` type, and returns the value.

## Syntax

```
BSON_EXTRACT_BOOL(<input> [, path_key_1, path_key_2,.., path_key_n])
```

## Arguments

* `<input>`: A valid BSON document or an expression that evaluates to a valid BSON document.
* `<path>`: A comma-separated list of dictionary keys or array positions (zero-based index).

## Return Type

SingleStore `TINYINT` type.

## Remarks

The following table specifies the value returned by `BSON_EXTRACT_BOOL()` for each input value:

| Input Value                                | Output Value |
| ------------------------------------------ | ------------ |
| BSON boolean`true`                         | 1            |
| BSON boolean`false`                        | 0            |
| BSON`NULL`                                 | `NULL`       |
| Any other value or a non-boolean BSON type | `NULL`       |

## Examples

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

The following examples extract a boolean value:

```sql
SELECT BSON_EXTRACT_BOOL('{"a":{"b":true}}':>BSON, 'a', 'b') AS Result;

```

```output

+--------+
| Result |
+--------+
|      1 |
+--------+
```

```sql
SELECT BSON_EXTRACT_BOOL('{"a":{"b":false}}':>BSON, 'a', 'b') AS Result;

```

```output

+--------+
| Result |
+--------+
|      0 |
+--------+
```

***

Modified at: April 2, 2024

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

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