Product SiteDocumentation Site

11.2. Treat Expressions

A treat expression just forwards its operand value, but only after checking that a JSONiq value matches a given sequence type. If it is not the case, an error is raised.
Example 11.2. Treat as expression.
1 treat as integer,
"foo" treat as string,
{ "foo" : "bar" } treat as object,
({ "foo" : "bar" }, { "bar" : "foo" })
    treat as json-item+,
[ 1, 2, 3 ] treat as array?,
() treat as ()
Results:
1
"foo"
{
  "foo" : "bar"
}
{
  "foo" : "bar"
}
{
  "bar" : "foo"
}
[ 1, 2, 3 ]

Example 11.3. Treat as expression (failing).
1 treat as string
Error:
"xs:integer" cannot be treated as type xs:string