json:transform-to-json( $node as node(), [$config as map:map] ) as document-node()?
This function transforms an XML document to JSON using the default ("basic") strategy if none is supplied.
The supplied document (element or document node) is transformed to JSON using the default ("basic") strategy and returned as a document node containing a JSON node (object-node() or array-node()).
When the default "basic" strategy is used, the XML node
must be in the http://marklogic.com/xdmp/json/basic
namespace.
Note: Version of MarkLogic prior to 8.0.1 returned an xs:string. See https://docs.marklogic.com/guide/relnotes/chap4#id_92312
(: sample.xml must be inserted first. For reference: xdmp:document-insert("/sample.xml", <a><b><attr>d</attr><LABEL>c</LABEL></b></a>) :) xquery version "1.0-ml"; import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy"; let $config := json:config("full") => map:with("whitespace", "ignore") return json:transform-to-json( fn:doc("/sample.xml") , $config ) (: The following output is produced: { "a": { "_children": [ { "b": { "_children": [ { "attr": { "_children": ["d"]} }, { "LABEL": { "_children": ["c"] } } ] } } ] } } :)