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β abson_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 passNULLand 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
lengthgets set. π - upon failure:
NULLis 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
π COPYRIGHT π
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
- 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