json:set-item-at( $array as json:array, $pos as xs:double, $value as item()* ) as empty-sequence()
Sets a value in an array at a specified position.
Parameters | |
---|---|
array | An array. |
pos | The position to update. Invalid positions throw XDMP-ARRAYINDEXOUTOFBOUNDS |
value | A value. Empty sequences are allowed. |
let $array := json:to-array( ("a","b","c"), 5 ) let $put := json:set-item-at($array, 5 , <info>45683</info>) return <result>{$array}</result> => <result> <json:array xmlns:json="http://marklogic.com/xdmp/json"> <json:value xsi:type="xs:string">a</json:value> <json:value xsi:type="xs:string">b</json:value> <json:value xsi:type="xs:string">c</json:value> <json:value xsi:nil="true"/> <json:value><info>45683</info></json:value> </json:array> </result>
xquery version "1.0-ml"; let $array := json:to-array(("a", "z", "c")) return ( $array[2], json:set-item-at($array, 2, "b"), $array[2] ) => z b
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.