BSON_AS_RELAXED_EXTENDED_JSON(3)

πŸ’… BSON_AS_RELAXED_EXTENDED_JSON(3)

okay bestie, welcome to the libbson manual, section 3 β€” this one's about bson_as_relaxed_extended_json, and it's genuinely a little icon. no cap. ✨


🌸 SYNOPSIS 🌸

char *
bson_as_relaxed_extended_json (const bson_t *bson, size_t *length);

πŸŽ€ PARAMETERS πŸŽ€

  • bson β€” a bson_t. literally just your BSON document, the main character.
  • length β€” an optional place to stash the length of the resulting string. optional bestie, you can pass NULL and nobody will be mad.

πŸ¦‹ DESCRIPTION πŸ¦‹

so bson_as_relaxed_extended_json() encodes bson as a UTF-8 string in Relaxed Extended JSON. that's the whole vibe. πŸ’œ

heads up: for the actual rundown of Extended JSON formats, go peek at the MongoDB Extended JSON format docs β€” that's where the lore lives.

now the part everyone forgets 😭 β€” you are the one responsible for freeing that resulting UTF-8 encoded string. call bson_free() on it when you're done. don't just leave it lying around, that's not slay, that's a leak.

if length is non-NULL, it gets set to the length of the result in bytes. πŸ“


⭐ RETURNS ⭐

  • if it works: a newly allocated UTF-8 encoded string, and length gets set. πŸŽ‰
  • upon failure: NULL is returned. πŸ’€ that's it, that's the whole failure mode.

πŸ”₯ EXAMPLE πŸ”₯

bson_t *b = BCON_NEW("foo", BCON_INT32(123));
char *str = bson_as_relaxed_extended_json(b, NULL);
printf("Relaxed Extended JSON: %s\n", str);
// Prints:
// Relaxed Extended JSON: { "foo" : 123 }
bson_free(str);
bson_destroy(b);

look at that output. { "foo" : 123 }. absolutely ate. πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc


2009-present, MongoDB, Inc.


🫢 and that's the whole page, bestie β€” brought to you by libbson 2.5.6, dated Oct 09, 2026. go forth and free your strings. πŸ’–βœ¨

πŸ“¦ where this page comes from