---
name: "bson_validate_with_error"
section: "3"
platform: "linux"
package: "libbson-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/bson_validate_with_error"
---

# bson\_validate\_with\_error(3)

## SYNOPSIS

```
bool
bson_validate_with_error (const bson_t *bson,
                          bson_validate_flags_t flags,
                          bson_error_t *error);
```

## PARAMETERS

- •

  **bson**: A *bson\_t*.

- •

  **flags**: A bitwise-or of all desired *bson\_validate\_flags\_t*.

- •

  **error**: Optional *bson\_error\_t*.

## DESCRIPTION

Validates a BSON document by walking through the document and inspecting the keys and values for valid content.

You can modify how the validation occurs through the use of the **flags** parameter, see *bson\_validate\_flags\_t* for details.

## RETURNS

If **bson** passes the requested validations, returns true. Otherwise, returns false and if **error** is non-*NULL* it will be filled out with details.

The *bson\_error\_t* domain is set to **BSON\_ERROR\_INVALID**. Its code is set to one of the **bson\_validate\_flags\_t** flags indicating which validation failed; for example, if a key contains invalid UTF-8, then the code is set to **BSON\_VALIDATE\_UTF8**, but if the basic structure of the BSON document is corrupt, the code is set to **BSON\_VALIDATE\_NONE**. The error message is filled out, and gives more detail if possible.

To get the specific location of the error, use *bson\_validate\_with\_error\_and\_offset()* instead.

**SEE ALSO:**

```
bson_validate(), bson_validate_with_error_and_offset().
```

```
bson_visitor_t can be used for custom validation, Example Custom Validation.
```

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
