BSON_UTF8_ESCAPE_FOR_JSON(3)
π BSON_UTF8_ESCAPE_FOR_JSON(3) β¨
okay so bestie, this is a page from libbson's manual β the bson_utf8_escape_for_json function, to be exact. buckle up, it's actually so good π«Ά
πΈ SYNOPSIS πΈ
char *
bson_utf8_escape_for_json (const char *utf8, ssize_t utf8_len);
π PARAMETERS π
utf8β a UTF-8 encoded string, bestie. that's the vibe.utf8_lenβ how longutf8is, in bytes. or pass-1if it's NUL terminated and you're feeling lazy π
π¦ DESCRIPTION π¦
so this function allocates a brand-new string that matches utf8, except β plot twist β the special characters that JSON cares about get escaped. and yeah, the resulting string is also UTF-8 encoded. we stay consistent β¨
both " and \ characters get backslash-escaped. iconic behavior, honestly.
if a NUL byte shows up before utf8_len bytes, it gets converted to "\u0000". and the other non-ASCII characters in the input? preserved. untouched. main character energy π
now this part's important so listen up: the two-byte sequence "C0 80" is also interpreted as an internal NUL, for historical reasons. and just so we're clear, that sequence is considered invalid according to RFC3629. so like... it's giving legacy baggage, but we deal π
π RETURNS π
you get a newly allocated string back, and you should free it with bson_free() when utf8 is a valid UTF-8 string. or β if the (possibly invalid UTF-8) string could not be escaped β you get NULL. no notes π
π AUTHOR π
MongoDB, Inc
β COPYRIGHT β
2009-present, MongoDB, Inc.
and that's the whole page, bestie β no cap, you're now officially fluent in bson_utf8_escape_for_json π§π
signed off from version 2.5.6, dated Oct 09, 2026 β catch you in the next manpage, mwah π
π¦ 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