Loading TOC...

json:array-push

json:array-push(
   $array as json:array,
   $item as item()*
) as empty-sequence()

Summary

Push a value to the end of the array, increasing the size of the array by one.

Parameters
$array An array.
$item New entries.

Example

  let $a := json:to-array(1 to 3)
  let $_ := json:array-push($a, 4)
  return xdmp:to-json($a)
  => [1, 2, 3, 4]

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

Comments

The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • It would be nice if adding a sequence behaved the same as adding one item. An item just appends to the array as in the example, where a sequence becomes an array-in-an-array like [1,2,3,[4,5,6,7]]. I think it would fit with xQuery if this simply added to the array as single items do.
    • Agreed, I just ran into this problem as well.
      • I see what you're saying, but there is a work-around: <code> let $a := json:to-array(1 to 3) let $b := (5 to 7) let $_ := $b ! json:array-push($a, .) return xdmp:to-json($a) </code>
        • I ended up doing something very similar to this to fix it, but it just took me a bit to find where the problem was. This seems counter intuitive.