BSON_ARRAY_AS_JSON(3)

πŸ’… BSON_ARRAY_AS_JSON(3) β€” a libbson moment

ok so bestie, we're in the libbson section of the manual and today's main character is bson_array_as_json(). she's giving "turn my BSON into a cute little JSON array" energy. but listen β€” there's tea. β˜•


🚨 WARNING (read this first, fr fr)

Deprecated since version 1.29.0. Use bson_array_as_canonical_extended_json() and bson_array_as_relaxed_extended_json() instead β€” those use the same MongoDB Extended JSON format as all other MongoDB drivers, which is the whole point.

and if you're lowkey committed to the old ways and need to keep producing Legacy Extended JSON? then use bson_array_as_legacy_extended_json(). that's her replacement, she's right there. πŸ’–


✨ SYNOPSIS ✨

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

πŸŽ€ PARAMETERS πŸŽ€

  • bson β€” a bson_t. the lil guy we're encoding, obviously. πŸ’…
  • length β€” an optional location for the length of the resulting string. optional!! she doesn't have to be there if she doesn't want to.

πŸ¦‹ DESCRIPTION πŸ¦‹

ok so bson_array_as_json() encodes bson as a UTF-8 string using libbson's Legacy Extended JSON. and here's the iconic part β€” the outermost element gets encoded as a JSON array ([ ... ]), not a JSON document ({ ... }). she's an array girlie, not a document girlie. 🌈

not me forgetting to free it 😭 β€” the caller is responsible for freeing the resulting UTF-8 encoded string by calling bson_free() with the result. it's your string now bestie, take care of her. 🫢

if length is non-NULL, length will be set to the length of the result in bytes. numbers, we love to see it. ✨


⭐ RETURNS ⭐

  • if successful: a newly allocated UTF-8 encoded string, and length is set. slay. πŸ‘‘
  • upon failure: NULL is returned. πŸ’€

πŸ’œ AUTHOR

MongoDB, Inc β€” yes, the MongoDB girlies themselves.


2009-present, MongoDB, Inc.


ok that's the whole page, no cap. this was libbson manual page BSON_ARRAY_AS_JSON(3), version 1.30.13, dated Oct 09, 2026. go forth and encode responsibly, and remember: bson_free() her when you're done. bye bestie!! πŸŽ€βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from