Loading TOC...

MarkLogic Server 11.0 Product Documentation
json:to-array

json:to-array(
   [$items as item()*],
   [$limit as xs:double?],
   [$zero as item()?]
) as json:array

Summary

Constructs a json:array from a sequence of items.

Parameters
items The items to be used as elements in the constructed array.
limit The size of the array to construct. If the size is less than the length of the item sequence, only as "limit" items are put into the array. If the size is more than the length of the sequence, the array is filled with null values up to the limit.
zero The value to use to pad out the array, if necessary. By default the empty sequence is used.

Usage Notes

Use this function to construct an in-memory object that represents a JSON array, suitable for use with xdmp:to-json. This function does not produce an array node. To construct an array node, use the array-node constructor.

Example

xquery version "1.0-ml";

json:to-array(1 to 2)
=>
  json:array(
    <json:array xmlns:json="http://marklogic.com/xdmp/json"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <json:value xsi:type="xs:integer">1</json:value>
     <json:value xsi:type="xs:integer">2</json:value>
    </json:array>
  )

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.