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β abson_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 passNULLand 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 bybson_as_canonical_extended_json()andbson_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
lengthgets set. slay π - upon failure?
NULLis 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 π§
π COPYRIGHT π
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
- epel 10: libbson-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms