BSON_INIT_FROM_JSON(3)
π bson_init_from_json β the libbson glow-up where your JSON becomes a whole BSON β¨
okay so this one lives in the libbson manual, section 3, and it's literally the "turn my cute little JSON string into a real BSON object" function. bestie, it ate. let's get into it π
β¨ SYNOPSIS β¨
bool
bson_init_from_json (bson_t *bson,
const char *data,
ssize_t len,
bson_error_t *error);
πΈ PARAMETERS πΈ
bsonβ a pointer to an uninitializedbson_t. like, don't pre-dress it, she gets initialized inside, k? π«Άdataβ a UTF-8 encoded string holding valid JSON. must be valid, no cap πlenβ the length ofdatain bytes, excluding a trailing\0. or pass-1and it'll figure the length out withstrlen(). main character behavior honestly βerrorβ an optional spot to stash abson_error_t. optional optional, no pressure π
π¦ DESCRIPTION π¦
So bson_init_from_json() initializes a brand new bson_t by parsing the JSON it finds in data. iconic. β¨
The one rule: only a single JSON object may exist in data. more than one? then an error gets set and false comes back at you. periodt π
Also, data should be in MongoDB Extended JSON format. that's the vibe, iykyk.
π DEPRECATED BEHAVIOR π
heads up bestie, this stuff is deprecated. it works (for now) but do not build your whole personality on it.
- If there are multiple comma-separated JSONs in
data, the keys from all of them get merged into the returned BSON. fr fr. for example,{"a": 1},{"b": 2}gets parsed as{"a": 1, "b": 2}. chaos, but documented chaos π - If the first character encountered after the last valid JSON object is
{, then all following characters are just ignored and no error is set. she simply stops reading π otherwise, an error will be set andNULLreturned. - This deprecated behavior is subject to change in a future release. so likeβ¦ don't get attached? π
π₯ ERRORS π₯
Errors are propagated via the error parameter. that's it, that's the section π
π RETURNS π
Returns true if valid JSON was parsed, otherwise false and error is set. π
On success, bson is initialized and must be freed with bson_destroy(). otherwise bson is invalid. so please, free her, she deserves peace π
π§ AUTHOR π§
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
okay that's the whole page, mwah π«Ά this was libbson 2.5.6, dated Oct 09, 2026 β so like, go forth, parse one JSON object, free your bson_t, and slay ππβ¨
π¦ 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