xdmp.toJsonString( item as Sequence ) as String
Returns a string representing a JSON serialization of a given item sequence.
Parameters | |
---|---|
item | A Sequence, typically containing a JavaScript Object, whose JSON serialization is returned. If you pass in a single value, it is treated as a Sequence with that single item; therefore, if you pass in an array, the array is treated as a single value (not as one value for each item in the array). If you mean to pass in the values of each item in the array, then you can call xdmp.arrayValues on the array. |
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.
xdmp.toJsonString(["a",false]); => ["a", false]
xdmp.toJsonString( xdmp.fromJsonString('{ "a":111 }')); => {"a":111}