BSON_NEW_FROM_JSON(3)

πŸŽ€ BSON_NEW_FROM_JSON(3) πŸŽ€

okay bestie, welcome to the libbson manual page for bson_new_from_json() β€” this one is literally the glow-up from JSON to BSON, and yes, the vibes are immaculate ✨


✨ SYNOPSIS ✨

bson_t *
bson_new_from_json (const uint8_t *data, ssize_t len, bson_error_t *error);

🌸 PARAMETERS 🌸

  • data β€” A UTF-8 encoded string containing valid JSON. That's the main character right there πŸ‘‘
  • len β€” The length of data in bytes excluding a trailing \0 or -1 to determine the length with strlen(). So either you count it yourself or you let strlen() do its thing πŸ’…
  • error β€” An optional location for a bson_error_t. Optional, but lowkey your bestie when things go sideways 🫢

πŸ’… DESCRIPTION πŸ’…

The bson_new_from_json() function allocates and initializes a new bson_t by parsing the JSON found in data. It's giving "turn this text into BSON real quick" energy, no cap.

Only a single JSON object may exist in data β€” or an error will be set and NULL returned. One object, okay? Not a whole group chat of JSONs. πŸ™ˆ

⚠️ Deprecated behavior alert, bestie: If there are multiple comma-separated JSONs in data, the keys from all JSONs are merged in the returned BSON. For example, {"a": 1},{"b": 2} is parsed as {"a": 1, "b": 2}. If the first character encountered after the last valid JSON object is {, all following characters are ignored and no error is set. Otherwise, an error will be set and NULL returned. fr fr, that's the deprecated behavior, so don't act surprised πŸ’€

Errors

Errors are propagated via the error parameter. That's the whole mood: if something's wrong, it gets passed straight to your error. 🧚


πŸ”₯ RETURNS πŸ”₯

A newly allocated bson_t if successful, otherwise NULL and error is set. Slay when it works, check the error when it doesn't ✨


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc


2009-present, MongoDB, Inc.


mwah πŸ’‹ that's the whole page from libbson 2.5.6, dated Oct 09, 2026 β€” go forth and parse responsibly, bestie! πŸ¦‹πŸ’–

πŸ“¦ where this page comes from