Product SiteDocumentation Site

5.2. Basic operations

We now introduce the most basic operations you can perform in JSONiq.

5.2.1. Construction of sequences

5.2.1.1. Comma operator

Expr
Figure 5.13. Expr

Use a comma to concatenate two sequences, or even single items. This operator has the lowest precedence of all.
Example 5.31. Comma
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Result (run with Zorba):
1 2 3 4 5 6 7 8 9 10

Example 5.32. Comma
{ "foo" : "bar" }, [ 1 ]
Result (run with Zorba):
{ "foo" : "bar" } [ 1 ]

Sequences do not nest. You need to use arrays in order to nest.

5.2.1.2. Range operator

RangeExpr
Figure 5.14. RangeExpr

With the binary operator "to", you can generate larger sequences with just two integer operands.
Example 5.33. Range operator
1 to 10
Result (run with Zorba):
1 2 3 4 5 6 7 8 9 10

If one operand evaluates to the empty sequence, then the range operator returns the empty sequence.
Example 5.34. Range operator with the empty sequence
() to 10, 1 to ()
Result (run with Zorba):

Otherwise, if an operand evaluates to something else than a single integer or an empty sequence, an error is raised.
Example 5.35. Range operator with a type inconsistency
(1, 2) to 10
Result (run with Zorba):
An error was raised: sequence of more than one item can not be promoted to parameter type xs:integer? of function to()