MarkLogic Server 11.0 Product Documentation
json:transform-to-json-xml

json:transform-to-json-xml(
   $node as node(),
   [$config as map:map]
) as element()

Summary

This function transforms an XML document to JSON and returns an xml element.

Parameters
node The node to transform. If the config parameter is not supplied, or it is created from json:config('basic') then the node must be a document conforming to the schema produced by json:transform-from-json when called with the basic.
config If present, the configuration object representing the strategy, otherwise the 'basic' strategy is used.

Usage Notes

The supplied document (element or document node) is transformed to JSON using the default (basic) strategy and returned as an element. The element will be either a json:object or json:array element.

When the default "basic" strategy is used, the XML node must be in the http://marklogic.com/xdmp/json/basic namespace.

See Also

Example

xquery version '1.0-ml';
import module namespace json = "http://marklogic.com/xdmp/json"
    at "/MarkLogic/json/json.xqy";

json:transform-to-json-xml(
  <root>
    <key>value</key>
  </root>, 
  json:config("full"))

(:
The following JSON XML is produced:
<json:object xmlns:json="http://marklogic.com/xdmp/json" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <json:entry key="root">
    <json:value>
      <json:object>
	<json:entry key="_children">
	  <json:value>
	    <json:array>
	      <json:value>
		<json:object>
		  <json:entry key="key">
		    <json:value>
		      <json:object>
			<json:entry key="_children">
			  <json:value>
			    <json:array>
			     <json:value xsi:type="xs:string">value
			     </json:value>
			    </json:array>
			  </json:value>
			</json:entry>
		      </json:object>
		    </json:value>
		  </json:entry>
		</json:object>
	      </json:value>
	    </json:array>
	  </json:value>
	</json:entry>
      </json:object>
    </json:value>
  </json:entry>
</json:object> :)
    
Powered by MarkLogic Server | Terms of Use | Privacy Policy