xquerymarklogicxml-to-json

MarklLogic json:transform-to-json throws 'null' when element name is 'name'


When using json:transform-to-json with "custom" config, the value of my <name> element is transformed as "null". Instead, I expect the text of the <name> element to be displayed.

import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy";

let $myxml := <root><a>some text</a><name>some other text</name></root>

let $jsonConfig := json:config("custom")
    
return json:transform-to-json($myxml,$jsonConfig)

returns

{"root": {
"a": "some text", 
"name": null } }

I expect it to return

{"root": {
"a": "some text", 
"name": "some other text"
}}

Notes:

This is specific to me calling my element <name> and it works as expected if I call it something else (e.g. <names>). But I need to call it <name>.

I think this is a MarkLogic database setting, as it works in one of our databases but not in others in the same MarkLogic instance. None of the settings jump out to me as obviously relevant to JSON transformation.


Solution

  • I pinpointed the difference between the databases to solve this. On the MarkLogic admin page (ML 9), I selected a different database for the "schema database", and that solved the problem. There must be something in our schemas that causes this.