<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.toJSON.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.toJSON</api:function-name><api:suggest>xdmp.tojson</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>tojson</api:suggest><api:function-link mode="xquery" fullname="xdmp:to-json">/apidoc/8.0/xdmp:to-json.xml</api:function-link><api:function mode="javascript" name="toJSON" type="builtin" lib="xdmp" category="Extension" subcategory="JSON" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.toJSON"><api:name class="javascript">toJSON</api:name><api:summary>
  Constructs a JSON document.
</api:summary><api:params><api:param name="item" type="item()*"><api:param-description>
    A sequence of items from which the JSON document is to be constructed.
  </api:param-description><api:param-name>item</api:param-name><api:param-type>ValueIterator</api:param-type></api:param></api:params><api:return>Node</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">An <code>object-node()</code> is constructed from a
  <code>json:object</code>, a <code>map:map</code>, or an
  <code>object-node()</code>.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">An <code>array-node()</code> is constructed from a
  <code>json:array</code>, a sequence of multiple items, or an
  <code>array-node()</code>.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">A <code>null-node()</code> is constructed from an empty sequence or
     an <code>null-node()</code>.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">A <code>boolean-node()</code> is constructed from an
  <code>xs:boolean</code> or a <code>boolean-node()</code>.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">A <code>number-node()</code> is constructed from an
  <code>xs:integer</code>, a <code>xs:decimal</code>, a
  <code>xs:float</code>, a <code>xs:double</code>, or a
  <code>number-node()</code>. Integers with absolute value greater than
     9007199254740991 are excluded and instead construct <code>text()</code>
     nodes to avoid any loss of precision.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">A <code>text()</code> node is constructed from all other items.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">To serialize a JSON node to a string, use <code>xdmp:quote</code>.</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var object = {"a":111};
xdmp.toJSON(object)
=&gt;
{"a":111}
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp.toJSON({"foo":"bar"}).root.foo
=&gt; "bar"
</pre></api:example></api:function></api:function-page>