Atomic literals

Figure 8. Literal

Literal

Figure 9. NumericLiteral

NumericLiteral

Figure 10. IntegerLiteral

IntegerLiteral

Figure 11. DecimalLiteral

DecimalLiteral

Figure 12. DoubleLiteral

DoubleLiteral

Figure 13. StringLiteral

StringLiteral

Figure 14. BooleanLiteral

BooleanLiteral

Figure 15. NullLiteral

NullLiteral

The syntax for creating strings, numbers, booleans and nulls is identical to that of JSON (it is actually a more flexible superset, for example leading 0s are allowed, and a decimal literal can begin with a dot). Note 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. JSON's backslash escaping is supported in string literals. Also, like in JSON, double quotes are required and single quotes are forbidden.

Example 8. String literals

"foo"
      

Result (run with Zorba): foo


Example 9. String literals with escaping

"This is a line\nand this is a new line"
      

Result (run with Zorba): This is a line and this is a new line


Example 10. String literals with Unicode character escaping

"\u0001"
      

Result (run with Zorba): 


Example 11. String literals with a nested quote

"This is a nested \"quote\""
      

Result (run with Zorba): This is a nested "quote"


Example 12. Integer literals

42
      

Result (run with Zorba): 42


Example 13. Decimal literals

3.14
      

Result (run with Zorba): 3.14


Example 14. Double literals

+6.022E23
      

Result (run with Zorba): 6.022E23


Example 15. Boolean literals (true)

true
      

Result (run with Zorba): true


Example 16. Boolean literals (false)

false
      

Result (run with Zorba): false


Example 17. Null literals

null
      

Result (run with Zorba): null