---
name: "bson_string_t"
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_string_t"
---

# bson\_string\_t(3)

**WARNING:**

Deprecated since version 1.29.0.

String Building Abstraction

## SYNOPSIS

```
#include <bson/bson.h>
typedef struct {
   char *str;
   uint32_t len;
   uint32_t alloc;
} bson_string_t;
```

## DESCRIPTION

*bson\_string\_t* is an abstraction for building strings. As chunks are added to the string, allocations are performed in powers of two.

This API is useful if you need to build UTF-8 encoded strings.

## EXAMPLE

```
bson_string_t *str;
str = bson_string_new (NULL);
bson_string_append_printf (str, "%d %s %f\n", 0, "some string", 0.123);
printf ("%s\n", str->str);
bson_string_free (str, true);
```

**TIP:**

You can call *bson\_string\_free()* with **false** if you would like to take ownership of **str-\>str**. Some APIs that do this might call **return bson\_string\_free (str, false);** after building the string.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
