2

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.

maifosz
  • 55
  • 6
  • What version of MarkLogic are you running? I just ran your code against 11.0.2 and it produced: `{"root":{"a":"some text", "name":"some other text"}}` – Mads Hansen Apr 13 '23 at 15:52

1 Answers1

1

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.

maifosz
  • 55
  • 6