BSON_ARRAY_AS_..._EXTENDED_JSON(3)
okay so bestie, this is the BSON_ARRAY_AS_..._EXTENDED_JSON(3) manual page from libbson π β yes, the title is a whole mouthful, but itβs literally just the legacy array-to-Extended-JSON girlie. Letβs get into it.
β¨ SYNOPSIS β¨
char *
bson_array_as_legacy_extended_json (const bson_t *bson, size_t *length)
π PARAMETERS π
bsonβ abson_t. Thatβs the thing getting encoded, bestie. πlengthβ an optional location for the length of the resulting string. Optional, so you can passNULLif youβre not feeling nosy. π
π DESCRIPTION π
So bson_array_as_legacy_extended_json() encodes bson as a UTF-8 string using libbson's Legacy Extended JSON. The outermost element is encoded as a JSON array ([ ... ]), rather than a JSON document ({ ... }) β thatβs the whole point of the array version, okay? π
This function is superseded by bson_array_as_canonical_extended_json() and bson_array_as_relaxed_extended_json(), which use the same MongoDB Extended JSON format as all other MongoDB drivers. So sheβs legacy, but she still serves. π
The caller is responsible for freeing the resulting UTF-8 encoded string by calling bson_free() with the result. Do not forget, bestie β thatβs your job, not libbsonβs. π«Ά
If non-NULL, length will be set to the length of the result in bytes. Ngl, that byte count is lowkey useful. β¨
π RETURNS π
- If successful: a newly allocated UTF-8 encoded string, and
lengthis set. Slay. β¨ - Upon failure:
NULLis returned. π
π¦ EXAMPLE π¦
Okay, example time β copy this exactly if youβre following along, fr fr:
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_legacy_extended_json(b, NULL);
printf("Legacy Extended JSON array: %s\n", str);
// Prints:
// Legacy Extended JSON array: [ 1, "bar" ]
bson_free(str);
bson_destroy(b);
π AUTHOR π
MongoDB, Inc β the author, no cap. π
π COPYRIGHT π
2009-present, MongoDB, Inc. β copyright line, kept cute and exact. π
mwah π β thatβs the whole page, bestie, and itβs giving libbson 2.5.6, dated Oct 09, 202, periodt πβ¨
π¦ 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