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. Usebson_array_as_canonical_extended_json()andbson_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β abson_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
lengthis set. slay. π - upon failure:
NULLis returned. π
π AUTHOR
MongoDB, Inc β yes, the MongoDB girlies themselves.
πΈ COPYRIGHT
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
- fedora 43: libbson-devel 1.30.13-1.fc43 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- fedora 43: libbson-devel 1.30.13-1.fc43 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms