This page was generated
August  8,  2011
2:23  AM
XQuery Built-In and Modules Function Reference

Built-In: Extension - JSON Functions

The JSON built-in functions serialize XQuery items to JSON and read a JSON string and create XQuery items from it. JSON (JavaScript Object Notation) is a data-interchange format popular mechanism for passing data from JavaScript to other programming environments.

Function Summary
xdmp:from-json Parses a string as JSON, returning an item sequence.
xdmp:to-json Returns a string representing a JSON serialization of a given item sequence.
Function Detail
xdmp:from-json(
$arg as xs:string
)  as   item()*
Summary:

Parses a string as JSON, returning an item sequence.

Parameters:
$arg : JSON input to be parsed.

Usage Notes:

JSON objects are parsed as maps.

The JSON null value is represented as the empty sequence.

Nested arrays in JSON are flattened out.

Any codepoints in the JSON string that aren't allowed in XML are rejected and an error is thrown.


Example:
  xdmp:from-json('["a", false]')
  => ("a", fn:false())
  

xdmp:to-json(
$item as item()*
)  as   xs:string
Summary:

Returns a string representing a JSON serialization of a given item sequence.

Parameters:
$item : The item sequence whose JSON serialization is returned.

Usage Notes:

XML nodes are serialized to JSON strings.

JSON has no serialization for infinity, not a number, and negative 0, therefore if you try and serialize INF, -INF, NaN, or -0 as JSON, an exception is thrown. If you want to represent these values in some way in your serialized JSON, then you can catch the exception (with a try/catch, for example) and provide your own value for it.

XQuery maps (map:map types) serialize to JSON name-value pairs.


Example:
  xdmp:to-json(("a",fn:false()))
   => ["a", false]