.\" Man page generated from reStructuredText. . .TH "BSON_AS_JSON" "3" "Jun 04, 2021" "1.17.6" "libbson" .SH NAME bson_as_json \- bson_as_json() . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C char * bson_as_json (const bson_t *bson, size_t *length); .ft P .fi .UNINDENT .UNINDENT .SH PARAMETERS .INDENT 0.0 .IP \(bu 2 \fBbson\fP: A \fBbson_t\fP\&. .IP \(bu 2 \fBlength\fP: An optional location for the length of the resulting string. .UNINDENT .SH DESCRIPTION .sp The \fBbson_as_json()\fP function shall encode \fBbson\fP as a UTF\-8 string using libbson\(aqs legacy JSON format. This function is superseded by \fBbson_as_canonical_extended_json()\fP and \fBbson_as_relaxed_extended_json()\fP, which use the same \fI\%MongoDB Extended JSON format\fP as all other MongoDB drivers. .sp The caller is responsible for freeing the resulting UTF\-8 encoded string by calling \fBbson_free()\fP with the result. .sp If non\-NULL, \fBlength\fP will be set to the length of the result in bytes. .SH RETURNS .sp If successful, a newly allocated UTF\-8 encoded string and \fBlength\fP is set. .sp Upon failure, NULL is returned. .SH EXAMPLE .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #include int main () { bson_t bson; char *str; bson_init (&bson); BSON_APPEND_UTF8 (&bson, "0", "foo"); BSON_APPEND_UTF8 (&bson, "1", "bar"); str = bson_as_json (&bson, NULL); /* Prints * { "0" : "foo", "1" : "bar" } */ printf ("%s\en", str); bson_free (str); bson_destroy (&bson); } .ft P .fi .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .