Hi,

While upgrading ML6 to ML8, I needed to modify the JSON format and I did it
based on my understanding on ML8 JSON handling however my senior is not
convince with this solution so wanted to know if my approach is not best
fit and could be better solution.


Please someone take a look on my code and suggest any better solution?


let $input := '{"docTitle":"histories: Search for apple", "type":"Search",
"searchParameter":{"page":1, "pageLength":10}}'

When I am using json:transform-from-json($input), getting below output with
namespace  "http://marklogic.com/xdmp/json/basic";

<json type="object" xmlns="http://marklogic.com/xdmp/json/basic";>
<docTitle type="string">
histories: Search for apple
</docTitle>
<type type="string">
Search
</type>
<searchParameter type="object">
<page type="number">
1
</page>
<pageLength type="number">
10
</pageLength>
</searchParameter>

</json>


However I wanted the results with the namespace "http://marklogic.com/json";
so I have coded like below,


let $custom :=

        let $config := jsonl:config("custom")

        return

          (

           map:put($config, "element-namespace", "http://marklogic.com/json";),


           $config

          )

  let $json := try{ (jsonl:transform-from-json($input, $custom)) } catch
($e) {()}

  let $json := <json type="object" xmlns="http://marklogic.com/json
">{$json}</json>

  return $json


*output:*

<json type="object" xmlns="http://marklogic.com/json";>
<docTitle>
histories: Search for apple
</docTitle>
<type>
Search
</type>
<searchParameter>
<page>
1
</page>
<pageLength>
10
</pageLength>
</searchParameter>

</json>


Regards,

Indy
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to