json.transformFromJson( json as Item, [config as Object] ) as Sequence
This function transforms a JSON document to XML using the default ("basic") strategy.
basic
) strategy and returned as an element.
const json = require('/MarkLogic/json/json.xqy'); let 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.transformFromJson(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> <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"> </empty> </fourthKey> <fifthKey type="null"> </fifthKey> <sixthKey type="array"> </sixthKey> </json> */
const json = require('/MarkLogic/json/json.xqy'); let 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 = (config, 'attribute-names' , ('subKey' , 'boolKey' , 'empty' )) json.transformFromJson(j, config) /* The following output is produced: <object> <firstKey>first value</firstKey> <secondKey>first item</secondKey> <secondKey>second item</secondKey> <secondKey> </secondKey> <secondKey>third item</secondKey> <secondKey>false</secondKey> <thirdKey>3</thirdKey> <fourthKey> <subKey>sub value</subKey> <boolKey>true</boolKey> <empty> </empty> </fourthKey> <fifthKey> </fifthKey> </object> */
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.