---
name: "bson_validate"
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"
---

# bson\_validate(3)

## SYNOPSIS

```
bool
bson_validate (const bson_t *bson, bson_validate_flags_t flags, size_t *offset);
```

## PARAMETERS

- •

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

- •

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

- •

  **offset**: Optional location where the error offset will be written.

## 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 **offset** is non-*NULL* it will be written with the byte offset in the document where an error was detected.

To get more information about the specific validation failure, use *bson\_validate\_with\_error\_and\_offset()* instead.

**SEE ALSO:**

```
bson_validate_with_error(), 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.
