<?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_new_from_json">
  <info>
    <link type="guide" xref="bson_t" group="function"/>
  </info>
  <title>bson_new_from_json()</title>

  <section id="synopsis">
    <title>Synopsis</title>
    <synopsis><code mime="text/x-csrc"><![CDATA[bson_t *
bson_new_from_json (const uint8_t *data,
                    ssize_t        len,
                    bson_error_t  *error);
]]></code></synopsis>
  </section>

  <section id="parameters">
    <title>Parameters</title>
    <table>
      <tr><td><p>data</p></td><td><p>A UTF-8 encoded string containing valid JSON.</p></td></tr>
      <tr><td><p>len</p></td><td><p>The length of <code>data</code> in bytes excluding a trailing <code>\0</code> or -1 to determine the length with <code>strlen()</code>.</p></td></tr>
      <tr><td><p>error</p></td><td><p>An optional location for a <code xref="bson_error_t">bson_error_t</code>.</p></td></tr>
    </table>
  </section>

  <section id="description">
    <title>Description</title>
    <p>The <code>bson_new_from_json()</code> function allocates and initialize a new <code xref="bson_t">bson_t</code> by parsing the JSON found in <code>data</code>. Only a single JSON object may exist in <code>data</code> or an error will be set and NULL returned.</p>
  </section>

  <section id="errors">
    <title>Errors</title>
    <p>Errors are propagated via the <code>error</code> parameter.</p>
  </section>

  <section id="return">
    <title>Returns</title>
    <p>A newly allocated <code xref="bson_t">bson_t</code> if successful, otherwise NULL and <code>error</code> is set.</p>
  </section>

</page>
