<?xml version="1.0"?>
<page xmlns="http://projectmallard.org/1.0/"
      type="topic"
      style="function"
      xmlns:api="http://projectmallard.org/experimental/api/"
      xmlns:ui="http://projectmallard.org/experimental/ui/"
      id="bson_as_json">
  <info>
    <link type="guide" xref="bson_t" group="function"/>
  </info>
  <title>bson_as_json()</title>

  <section id="synopsis">
    <title>Synopsis</title>
    <synopsis><code mime="text/x-csrc"><![CDATA[char *
bson_as_json (const bson_t *bson,
              size_t       *length);
]]></code></synopsis>
  </section>

  <section id="parameters">
    <title>Parameters</title>
    <table>
      <tr><td><p>bson</p></td><td><p>A <link xref="bson_t">bson_t</link>.</p></td></tr>
      <tr><td><p>length</p></td><td><p>An optional location for the length of the resulting string.</p></td></tr>
    </table>
  </section>

  <section id="description">
    <title>Description</title>
    <p>The <link xref="bson_as_json">bson_as_json()</link> function shall encode <code>bson</code> as a JSON encoded UTF-8 string.</p>
    <p>The caller is responsible for freeing the resulting UTF-8 encoded string by calling <link xref="bson_free">bson_free()</link> with the result.</p>
    <p>If non-NULL, <code>length</code> will be set to the length of the result in bytes.</p>
  </section>

  <section id="return">
    <title>Returns</title>
    <p>If successful, a newly allocated UTF-8 encoded string and <code>length</code> is set.</p>
    <p>Upon failure, NULL is returned.</p>
  </section>

  <section id="example">
    <title>Example</title>
    <listing>
      <title>bson_as_json</title>
      <code mime="text/x-csrc"><![CDATA[char *str = bson_as_json (doc, NULL);
printf ("%s\n", str);
bson_free (str);]]></code>
    </listing>
  </section>

</page>
