Version 3 1

XQuery 3.1 became a W3C Recommendation on 21 March 2017. It extends XQuery to support JSON as well as XML, adding maps and arrays to the data model along with new expressions and functions to work with them. XQuery 3.1 remains the current, full Recommendation-level version.

XQuery 4.0 is under active development by the W3C's XQuery and XSLT Extensions Community Group (QT4CG) as a Community Group draft. As of early 2026 it is not yet an official W3C Recommendation and continues to evolve; it builds on XPath 4.0 (see XPath), a superset of XPath 3.1 that adds native JSON support and many new functions.

Maps

A map is a sequence of key/value pairs. map:remove returns a new map with a key removed; map:merge combines several maps into one; a map is itself callable as a function of its key.

let $m1 := map {'abc':123, 1:'hello'},
     $m2 := map:remove($m1,'abc'),
     $m3 := map:merge (for $i in 1 to 5
                                    return map {$i: 'value'||$i})
return (map:keys($m1),
           $m1('abc'),
           deep-equal($m1,$m2))

1 abc 123 false

Arrays

An array is an ordered sequence of members, each of which may itself be a sequence. Square-bracket notation [...] constructs an array whose members are its comma-separated expressions; the keyword form array {...} instead flattens each comma-separated expression's items into separate members.

let $a := [(1,2),3],                            (: two members :)
     $b := array {1 to 2,3},                 (: three members :)
     $c := array:size($a),                     (: 2 :)
     $d := $b(1),                                 (: 1 :)
     $e := [1,2,3]=2,                           (: true :)
     $f := function ($x as xs:integer*){count($x)}
return $f([1 to 5])                              (: 5 :)
The unary lookup operator ? looks up map or array members: ?* returns all values, ?key or ?N returns the value for a given key or position, and ?(...) looks up several keys/positions at once.

let $m := map {'R':'red', 'G':'green', 'B':'blue'}
return ($m?*,                              (: red green blue :)
           map:keys($m) ! $m(.)      (: red green blue :)
           $m?R,                              (: red :)
           $m?2,                              (: green :)
           $m?('G',3))                       (: green blue :)

Arrow operator

The arrow operator => pipes the expression on its left as the first argument into the function call on its right, letting a chain of function calls read left to right instead of nesting.

'w e l c o m e'
=> upper-case() => tokenize() => string-join('-')

W-E-L-C-O-M-E

Map and array functions

Selected functions added for maps and arrays, plus other functions introduced alongside JSON support: