Hi, Indrajeet: In MarkLogic 8, you would typically store JSON directly as native JSON and not converted to XML. The direct approach will improve performance and maintainability.
In the particular case, xdmp:unquote() will turn the input string into a JSON document that can be inserted into the database. The particular case looks like the input to a search request. Is there is a specific reason it must be encoded as XML? Erik Hennum ________________________________ From: general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.com] on behalf of Indrajeet Verma [indrajeet.ve...@gmail.com] Sent: Monday, May 04, 2015 6:00 AM To: MarkLogic Developer Discussion Subject: [MarkLogic Dev General] json namespace changes in json:transform-from-json($input) 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 General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general