Hi

I got a work around for the issue with JSON and am sharing for our future 
reference

I am going through ML 7 documentation and found that we have new search options 
now and one among them is result-decorator

https://docs.marklogic.com/guide/search-dev/query-options#id_63172

I used custom code as below (custom result-decorator)

xquery version "1.0-ml";

module namespace dec = "http://hmh.com/decorator";;

declare function dec:decorator($uri as xs:string) as node()*
{
let $format := xdmp:get-request-field("format")

return
(
if (empty($format)) then ()
else attribute format { $format }
)
};

The above code ensures that format will be same as user request and am getting 
results as expected now.

Regards,
Gnana(GP)


Message: 7
Date: Tue, 15 Jul 2014 11:17:20 +0000
From: <gnanaprakash.bodire...@cognizant.com>
Subject: [MarkLogic Dev General] How to get XML document as json using
        REST    API in MarkLogic 7
To: <general@developer.marklogic.com>
Message-ID:
        <40dd2b6a3a9bee4ba85c1323bf868bcc26d6f...@ctsinchnsxmbh.cts.com>
Content-Type: text/plain; charset="us-ascii"

Hi

Is there any way to get an XML document in JSON format in MarkLogic 7 using 
REST API?

In ML 6, I used custom transformation on raw document where I am converting XML 
document into JSON and returning it.

But in ML 7, the same code is not working because of REST API Changes. 
Converted JSON is returning as a string instead of an object.

Below is the code snippet in ML 7 Rest API, where it is fetching document 
mimetype ignoring the format we specify in REST URL.

let $uri-mimetype := xdmp:uri-content-type($uri)
    let $is-unknown   := ($uri-mimetype eq "application/x-unknown-content-type")
    let $format       :=
        let $mimetype-format :=
            if ($is-unknown) then ()
            else eput:get-outbound-type-format($uri-mimetype)
        let $uri-format      :=
            if ($is-unknown) then ()
            else if (exists($mimetype-format))
            then $mimetype-format
            else xdmp:uri-format($uri)
        return
            if (exists($uri-format))
            then $uri-format
            else eput:get-node-format($result)

if I change the above code to use the format I specy in REST URL to "json", 
everything is working as usual.

Can anyone suggest me if it is good to change the logic above to use the format 
parameter of REST API and emit the JSON? (if format=json then use as is else 
default logic)

Regards,
Gnanaprakash Bodireddy
Sr. Associate - Projects, Dublin Ireland

This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
If you are not the intended recipient(s), please reply to the sender and 
destroy all copies of the original message. Any unauthorized review, use, 
disclosure, dissemination, forwarding, printing or copying of this email, 
and/or any action taken in reliance on the contents of this e-mail is strictly 
prohibited and may be unlawful. Where permitted by applicable law, this e-mail 
and other e-mail communications sent to and from Cognizant e-mail addresses may 
be monitored.
_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to