Loading TOC...

json:to-array

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

Summary

Constructs an array from a sequence of items.

Parameters
items A sequence of items.
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.

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.