BSON_AS_LEGACY_EXTENDED_JSON(3)

πŸ’… bson_as_legacy_extended_json(3) πŸ’…

okay bestie, welcome to the libbson manual, section 3 πŸŽ€ this one's all about bson_as_legacy_extended_json and honestly? she's a legacy icon but she's also kind of retired, so let's get into it ✨


🌸 SYNOPSIS 🌸

char *
bson_as_legacy_extended_json (const bson_t *bson, size_t *length)

πŸ¦‹ PARAMETERS πŸ¦‹

  • bson β€” a bson_t. that's the thing you're converting, no cap πŸ’–
  • length β€” an optional spot to stash the length of the resulting string. optional optional, like you can literally pass NULL and she won't be mad πŸ™ˆ

✨ DESCRIPTION ✨

so bson_as_legacy_extended_json() takes bson and encodes it as a UTF-8 string using libbson's Legacy Extended JSON πŸ‘‘

🚨 okay real talk: this function is superseded by bson_as_canonical_extended_json() and bson_as_relaxed_extended_json(), which use the same MongoDB Extended JSON format as all the other MongoDB drivers. so like… she still works, but she's giving "still on the family plan" energy πŸ’€

the caller is responsible for freeing the resulting UTF-8 encoded string β€” you do that by calling bson_free() with the result. don't just leave her hanging, that's a memory leak and the vibe check will NOT pass 😭

if length is non-NULL, it will be set to the length of the result in bytes. yes, bytes. not characters. bytes, bestie 🫢

πŸ”₯ RETURNS πŸ”₯

  • if it works out? a newly allocated UTF-8 encoded string, and length gets set. slay πŸ’–
  • upon failure? NULL is returned. we don't talk about that ✨

🌈 EXAMPLE 🌈

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

see how she bson_free'd and bson_destroy'd at the end? that's the main character energy we're looking for πŸ‘‘πŸ’…

πŸŽ€ AUTHOR πŸŽ€

MongoDB, Inc β€” the icons themselves 🧚

2009-present, MongoDB, Inc. πŸ“


and that's the whole page, bestie 🌟 written for libbson version 2.5.6, dated Oct 09, 2026, and logged forever under BSON_AS_LEGACY_EXTENDED_JSON(3) ⭐ mwah πŸ’‹

πŸ“¦ where this page comes from