BSON_ARRAY_AS_...D_EXTENDED_JSON(3)
π
BSON_ARRAY_AS_...D_EXTENDED_JSON(3) π
okay bestie, this is the libbson manual page for turning a BSON array into Relaxed Extended JSON β and yes, the function name in the title is doing its own little abbreviation moment. iykyk. letβs get into it. π¦
β¨ SYNOPSIS β¨
char *
bson_array_as_relaxed_extended_json (const bson_t *bson, size_t *length);
π PARAMETERS π
bsonβ abson_t. thatβs the BSON thing weβre about to encode, bestie.lengthβ an optional location for the length of the resulting string. optional, like your third coffee of the day. β
πΈ DESCRIPTION πΈ
okay so the description says bson_as_relaxed_extended_json() encodes bson as a UTF-8 string in Relaxed Extended JSON. and the way it does it? the outermost element gets encoded as a JSON array ([ ... ]), not as a JSON document ({ ... }). itβs giving βarray main character energy,β fr fr. π
for the whole lore on the Extended JSON formats, see MongoDB Extended JSON format.
you, the caller, are responsible for freeing the resulting UTF-8 encoded string by calling bson_free() with the result. no cap, donβt forget this part. π«Ά
if length is non-NULL, length will be set to the length of the result in bytes.
β RETURNS β
if it slays and everything works: a newly allocated UTF-8 encoded string is returned, and length is set. periodt. β¨
upon failure: 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_relaxed_extended_json(b, NULL);
printf("Relaxed Extended JSON array: %s\n", str);
// Prints:
// Relaxed Extended JSON array: [ 1, "bar" ]
bson_free(str);
bson_destroy(b);
bestie, seriously:bson_free(str)andbson_destroy(b)are right there in the example. donβt leave them on read. π
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
kisses and clean builds π β this came from the libbson manual, version 2.5.6, dated Oct 09, 20 (yes, the footer really ends like that, and we respect the mystery π).
π¦ 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