Cast expressions

JSONiq follows the W3C standard for ordered and unordered expressions. The following explanations, provided as an informal summary for convenience, are non-normative.

Figure 67. CastExpr

CastExpr

A cast expression casts a JSONiq value to a given atomic type. The resulting value is annotated with this type.

Example 160. Cast as expression

"1" cast as integer
      

Result (run with Zorba): 1


Example 161. Cast as expression

"foo" cast as integer
      

Result (run with Zorba): An error was raised: "foo": value of type xs:string is not castable to type xs:integer


Example 162. Cast as expression

"2013-04-02" cast as date
      

Result (run with Zorba): 2013-04-02


Example 163. Cast as expression

() cast as date
      

Result (run with Zorba): An error was raised: empty sequence can not be cast to type with quantifier '1'


Example 164. Cast as expression

("2013-04-02", "2013-04-03") cast as date
      

Result (run with Zorba): An error was raised: sequence of more than one item can not be cast to type with quantifier '1' or '?'


The question mark allows for an empty sequence.

Example 165. Cast as expression

() cast as date?
      

Result (run with Zorba): 


Example 166. Cast as expression

"2013-04-02" cast as date?
      

Result (run with Zorba): 2013-04-02