Loading TOC...

MarkLogic 10 Product Documentation
xdmp:to-json-string

xdmp:to-json-string(
   $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-string(("a",fn:false()))
   => ["a", false]

Example

xdmp:to-json-string(
  xdmp:from-json-string('{ "a":111 }'))
=>
{"a":111}

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.