Treat 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 65. TreatExpr

TreatExpr

A treat expression checks that a JSONiq value matches a given sequence type. If it is not the case, an error is raised.

Example 147. Treat as expression

1 treat as integer
      

Result (run with Zorba): 1


Example 148. Treat as expression

1 treat as string
      

Result (run with Zorba): An error was raised: "xs:integer" cannot be treated as type xs:string


Example 149. Treat as expression

"foo" treat as string
      

Result (run with Zorba): foo


Example 150. Treat as expression

{ "foo" : "bar" } treat as object
      

Result (run with Zorba): { "foo" : "bar" }


Example 151. Treat as expression

({ "foo" : "bar" }, { "bar" : "foo" }) treat as json-item+
      

Result (run with Zorba): { "foo" : "bar" } { "bar" : "foo" }


Example 152. Treat as expression

[ 1, 2, 3 ] treat as array?
      

Result (run with Zorba): [ 1, 2, 3 ]


Example 153. Treat as expression

() treat as ()
      

Result (run with Zorba):