Product SiteDocumentation Site

Chapter 5. Construction of Items

5.1. Atomic Literals
5.1.1. String Literals
5.1.2. Number Literals.
5.1.3. Boolean and Null Literals
5.2. Object Constructors
5.3. Array Constructors
5.4. Composing Constructors
As we just saw, the items (objects, arrays, strings, ...) mentioned in Chapter 2, The JSON Syntax are constructed exactly as they are constructed in JSON. In a way, any JSON building block is also a well-formed JSONiq query which just "returns itself" (more precisely: its counterpart in the JSONiq Data Model)!

5.1. Atomic Literals

5.1.1. String Literals

The syntax for creating strings is identical to that of JSON. No surprise here. JSON's backslash escaping is supported, and like in JSON, double quotes are required and single quotes are forbidden.
Example 5.1. String literals.
"foo",
"This is a line\nand this is a new line",
"\u0001",
"This is a nested \"quote\""
Results:
"foo"
"This is a line
and this is a new line"
""
"This is a nested "quote""

5.1.2. Number Literals.

The syntax for creating numbers is identical to that of JSON.
Example 5.2. Number literals (integer, decimal and double literals)
42,
3.14,
-6.022E23
Results:
42
3.14
-6.022E23

Well, not quite. Actually, JSONiq allows a more flexible superset. In particular:
  • leading 0s are allowed
  • a decimal literal can begin or end with a dot
  • a number may begin with a + sign
Example 5.3. A more general literal syntax.
042,
.1415926535,
42.,
+6.022E23
Results:
42
0.1415926535
42
6.022E23

Remember that JSONiq distinguishes between integers (no dot, no scientific notation), decimals (dot but no scientific notation), and doubles (scientific notation). As expected, an integer literal creates an atomic of type integer, and so on. No surprises either.

5.1.3. Boolean and Null Literals

There is not much to say actually -- boolean literals build boolean atomics, the null literal builds a null atomic, so no worries here, the world is in order. You might as well want to move to the next section.
Example 5.4. Boolean and null literals.
true,
false,
null
Results:
true
false
null