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 β€” a bson_t. That’s the thing getting encoded, bestie. πŸ’œ
  • length β€” an optional location for the length of the resulting string. Optional, so you can pass NULL if 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 length is set. Slay. ✨
  • Upon failure: NULL is 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. πŸ‘‘

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