json:transform-from-json( $json as item(), [$config as map:map] ) as item()*
This function transforms a JSON document to XML using the default ("basic") strategy.
basic
) strategy and returned as an element.
xquery version "1.0-ml"; import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy"; declare variable $j := '{ "first Key":"first value", "secondKey":["first item","second item",null,"third item",false], "thirdKey":3, "fourthKey":{"subKey":"sub value", "boolKey" : true, "empty" : null } ,"fifthKey": null, "sixthKey" : [] }' ; json:transform-from-json( $j) (: The following output is produced: <json type="object" xmlns="http://marklogic.com/xdmp/json/basic"> <first_20_Key type="string">first value</first_20_Key> <secondKey type="array"> <item type="string">first item</item> <item type="string">second item</item> <item type="null"/> <item type="string">third item</item> <item type="boolean">false</item> </secondKey> <thirdKey type="number">3</thirdKey> <fourthKey type="object"> <subKey type="string">sub value</subKey> <boolKey type="boolean">true</boolKey> <empty type="null"/> </fourthKey> <fifthKey type="null"/> <sixthKey type="array"/> </json> :)
xquery version "1.0-ml"; import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy"; declare variable $j := '{ "object" : { "firstKey":"first value", "secondKey":["first item","second item","","third item",false], "thirdKey":3, "fourthKey":{"subKey":"sub value", "boolKey" : true, "empty" : null } ,"fifthKey": null, "sixthKey" : [] }}' ; let $config := json:config("custom") , $cx := map:put( $config, "attribute-names" , ("subKey" , "boolKey" , "empty" ) ) return json:transform-from-json( $j, $config ) (: The following output is produced: <object> <firstKey>first value</firstKey> <secondKey>first item</secondKey> <secondKey>second item</secondKey> <secondKey/> <secondKey>third item</secondKey> <secondKey>false</secondKey> <thirdKey>3</thirdKey> <fourthKey subKey="sub value" boolKey="true" empty=""/> <fifthKey/> </object> :)