MarkLogic 9 Product Documentation
json.transformToJson

json.transformToJson(
   node as Node,
   [config as Object]
) as Node?

Summary

This function transforms an XML document to JSON using the default ("basic") strategy if none is supplied.

Parameters
node The node to transform. The node must be a node that was transformed from JSON (for example, as the result of a json:transform-from-json call with the basic strategy or from JSON that was loaded using the REST API).
config The configuration object representing the strategy.

Usage Notes

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

See Also

Example

/* sample.xml must be inserted first. 
For reference: 
declareUpdate();
xdmp.documentInsert('/sample.xml', fn.head(xdmp.unquote('<a><b><attr>d</attr><LABEL>c</LABEL></b></a>'))); */

const json = require('/MarkLogic/json/json.xqy');
 
let config = json.config('full') ,
config.whitespace = 'ignore';
json.transformToJson( cts.doc('/sample.xml') , config );

/* The following output is produced: 
{
  "a": {
    "_children": [ { "b": {
          "_children": [
            {
              "attr": {
                "_children": ["d"] } },
            {
              "LABEL": {
                "_children": ["c"] }
            }
          ]
        }
      }
    ]
  }
}
*/
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy