BSON_ARRAY_AS_...L_EXTENDED_JSON(3)
π BSON_ARRAY_AS_...L_EXTENDED_JSON(3) π
okay so this is a libbson page, bestie β yes the title got a little cropped in the header (BSON_ARRAY_AS_...L_EXTENDED_JSON(3)), don't worry about it, that's just how it's filed π
β¨ SYNOPSIS β¨
char *
bson_array_as_canonical_extended_json (const bson_t *bson, size_t *length);
π«Ά PARAMETERS π«Ά
bsonβ abson_t. that's the thing getting encoded, periodt.lengthβ an optional spot to stash the length of the resulting string. optional!! so you can passNULLand nobody's mad π
πΈ DESCRIPTION πΈ
bson_array_as_canonical_extended_json() takes bson and encodes it as a UTF-8 string in Canonical Extended JSON. the way it does this: the outermost element gets encoded as a JSON array ([ ... ]), and not as a JSON document ({ ... }). highkey an important distinction, iykyk π¦
for the whole rundown of Extended JSON formats, go see the MongoDB Extended JSON format docs. π
β οΈ the caller is responsible for freeing the resulting UTF-8 encoded string β call bson_free() on the result. do not ghost it, do not leak it. free your girl π
if length is non-NULL, it gets set to the length of the result in bytes. π
π₯ RETURNS π₯
if it works out: a newly allocated UTF-8 encoded string, and length gets set. slay β¨
if it does not work out: NULL is returned. π
π§ EXAMPLE π§
bson_t *b = BCON_NEW("0", BCON_INT32(1), "1", BCON_UTF8("bar"));
// The document for an array is a normal BSON document with integer values for the keys, starting with 0 and
// continuing sequentially.
char *str = bson_array_as_canonical_extended_json(b, NULL);
printf("Canonical Extended JSON array: %s\n", str);
// Prints:
// Canonical Extended JSON array: [ { "$numberInt" : "1" }, "bar" ]
bson_free(str);
bson_destroy(b);
not the [ { "$numberInt" : "1" }, "bar" ] ate and left literally no crumbs π₯ see how the keys are just "0" and "1"? an array's underlying document is a totally normal BSON doc with integer values for keys, starting at 0 and going sequentially. iconic behavior fr fr π
π AUTHOR π
MongoDB, Inc π«Ά
π COPYRIGHT π
2009-present, MongoDB, Inc.
π remember:bson_free(str)thenbson_destroy(b). clean up ur room, bestie π
ok that's the whole page!! lots of love from libbson 2.5.6, dated Oct 09 (the year got ate by the header in the footer, ngl β 20... is all we got π), and yes the footer font is huge, that's the vibe check, bye π
π
π¦ 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