BSON_AS_JSON(3)

πŸ’– BSON_AS_JSON πŸ’–

okay bestie, welcome to BSON_AS_JSON(3) from the libbson manual ✨ this one's a little bittersweet because she's deprecated, but she still works and we're gonna learn her fr fr 🫢


⚠️ WARNING ⚠️

Deprecated since version 1.29.0: use bson_as_canonical_extended_json() and bson_as_relaxed_extended_json() instead β€” those ones use the same MongoDB Extended JSON format as literally every other MongoDB driver, so you're speaking the same language as the whole squad 🌈

And if you're dead set on continuing to produce Legacy Extended JSON, then use bson_as_legacy_extended_json(). that's the move πŸ’…

not me warning you before I even say what the function does 😭 that's how serious this is, bestie.

✨ SYNOPSIS ✨

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

πŸŽ€ PARAMETERS πŸŽ€

  • bson β€” a bson_t. yeah. that's the whole description. she's lowkey mysterious πŸ™ˆ
  • length β€” an optional location for the length of the resulting string.

πŸ¦‹ DESCRIPTION πŸ¦‹

bson_as_json() encodes bson as a UTF-8 string using libbson's Legacy Extended JSON. that's the whole vibe 🌸

and listen β€” the caller is responsible for freeing the resulting UTF-8 encoded string by calling bson_free() with the result. yes YOU. it's your string now, you have to take care of it 😭 don't just leave it there, that's not main character energy, that's a memory leak πŸ’€

if length is non-NULL, length will be set to the length of the result in bytes. so if you pass a pointer, she fills you in on the tea πŸ‘‘


πŸ’œ RETURNS πŸ’œ

if it works out? you get a newly allocated UTF-8 encoded string, and length gets set. slay πŸŽ‰

upon failure, NULL is returned. and that's it. no string, no length, just NULL and vibes 😭

always check for NULL, bestie. always. iykyk πŸ’…

πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” iconic, honestly 🌟


2009-present, MongoDB, Inc.


and that's the page!! this was BSON_AS_JSON(3) from libbson version 1.30.13, dated Oct 09, 2026 🫢 go forth and use the extended JSON functions instead, bestie, you got this πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from