MarkLogic 12 EA 1 Product Documentation
xdmp.fromJSON

xdmp.fromJSON(
   arg as Node
) as Sequence

Summary

Atomizes a JSON node, returning a JSON value.

Parameters
arg A node of kind object-node(), array-node(), text(), number-node(), boolean-node(), null-node(), or document-node().

Usage Notes

An object-node() atomizes as a json:object.

An array-node() atomizes as a json:array.

A null-node() atomizes as an empty sequence.

A boolean-node() atomizes as an xs:boolean.

A number-node() atomizes as an xs:integer, xs:decimal, or xs:double value.

A text() node atomizes as an xs:untypedAtomic.

A document-node() atomizes the same as its root.

This function returns the same result as fn:data, but it only works on JSON nodes.

To make a JSON node from a string, use xdmp:unquote with the "format-json" option.

Example

xdmp.fromJSON(xdmp.unquote('["a", null, false]',null,"format-json"));
=>
["a", null, false]
  

Example

var str = '[{"some-key":45683}, "this is a string", 123]';
var node = xdmp.unquote(str,null,"format-json");
xdmp.fromJSON(node);
=>
[{"some-key":45683}, "this is a string", 123]
Powered by MarkLogic Server | Terms of Use | Privacy Policy