Hi Erik
Using below code is not giving me format=json. <search:snippet> <json type="object" xmlns="http://marklogic.com/xdmp/json/basic"> <key type="string">value</key> </json> </search:snippet> Using below code gave me json response in snippet but it is not the best approach as I am transforming it to json and back to xml for getting basic namespace. element search:snippet { json:transform-from-json(json:transform-to-json($result, $custom)) } Please find the below sample and code I am using for transformation, Sample XML: <resource xmlns="http://www.hmh.com/resource" id="12312432"> <HMH_ID>JY_GA14E_EBK_G01U03L14D1S50_0121</HMH_ID> <resource_type>type</resource_type> <display_title>Title</display_title> <language>en-US</language> </resource Transformation: let $custom := let $config := json:config("custom") return (map:put($config, "array-element-names",(xs:QName("res:grade"),xs:QName("res:keyword"))), map:put($config, "whitespace","ignore"), map:put($config, "text-value","value"), $config) return json:transform-to-json(cts:highlight($result, $query, fn:concat('<span class="hit">',$cts:text,'</span>')), $custom-config) we are using transform-to-json to get the json and we are using custom config as we have schema defined for the resource element. (this is used to retain the datatypes we defined) Regards, Gnana(GP) -----Original Message----- From: Erik Hennum [mailto:erik.hen...@marklogic.com] Sent: Monday, December 02, 2013 10:20 PM To: Bodireddy, Gnanaprakash (Cognizant); general@developer.marklogic.com Subject: RE: JSON issue in MarkLogic 7 Hi, Gnana: Thanks for expanding about the issue. I think I understand now. We did fix a bug in MarkLogic 7 that text documents were being treated as JSON in snippeting, which caused JSON parsers on the client to blow up. If the result document is persisted using the JSON façade (that is, stored as XML in the http://marklogic.com/xdmp/json/basic namespace), the REST API assumes that text output from a snippeting transform is JSON. Otherwise, the REST API assumes that the text output is text and quotes the text output for JSON. To generate JSON in a snippeting transform, you can emit XML in the http://marklogic.com/xdmp/json/basic namespace. The following snippeting transform: xquery version "1.0-ml"; module namespace jsnip = "http://ext/testjsonsnippet"; import module namespace search="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy"; declare default function namespace "http://www.w3.org/2005/xpath-functions"; declare option xdmp:mapping "false"; declare function jsnip:snippet( $result as node(), $ctsquery as schema-element(cts:query), $options as element(search:transform-results)? ) as element(search:snippet) { <search:snippet> <json type="object" xmlns="http://marklogic.com/xdmp/json/basic"> <key type="string">value</key> </json> </search:snippet> }; emits the following snippet output for a search request with format=json: "mimetype":"application/json","format":"json","snippet":{"key":"value"} You can transform JSON to the XML representation for JSON using the JSON library, as in: json:transform-from-json('{"key":"value"}') Or, once you're familiar with the data structure, it's straightforward to write a transform that emits the XML directly as in the sample above. Finally, one footnote about version numbers on the REST API. We increment the version number when the request signatures change -- that is, when we have to make fundamental backward-incompatible changes in the URIs or payloads. We don't increment the version number when the behaviour of the server changes. (After all, every bug fix creates a backward incompatibility, an incompatibility that improves the offering, but still a change.) If that doesn't address the issue, then it might help to share your transform code and a sample input document. Hoping that helps, Erik Hennum ________________________________________ From: gnanaprakash.bodire...@cognizant.com<mailto:gnanaprakash.bodire...@cognizant.com> [gnanaprakash.bodire...@cognizant.com] Sent: Tuesday, November 26, 2013 10:37 PM To: general@developer.marklogic.com<mailto:general@developer.marklogic.com>; Erik Hennum Subject: Re: JSON issue in MarkLogic 7 Hi Erik Yes, it's custom transformation I am using wherein I am converting XML to JSON to ensure my raw xml will be shown in JSON format. Everything is working fine in ML6 and in ML7. even though my JSON conversion is working, the content element is treating the JSON as string and wrapping it up with quotes (content: ""<<json value>> "") I have seen the decorator module in ML 7 is adding new attributes (mimetype and format) which are getting values from URI i.e. it is getting the format from URI every time which I believe is bug. Because as we are passing in a parameter format=json we expect the API to treat the document as JSON. I updated the decorator API code to test how it works by tracking back the URL using xdmp:get-request-url and get the specified format i.e. json and pass it to the format variable. After me updating the code it started working and I am getting JSON response as expected. As we are not supposed to change the MarkLogic Code I am trying to check whether it's a bug which will be resolved in future or I need to look for alternative approaches here. Regards, Gnana(GP) Date: Tue, 26 Nov 2013 12:22:53 +0000 From: Erik Hennum <erik.hen...@marklogic.com<mailto:erik.hen...@marklogic.com>> Subject: Re: [MarkLogic Dev General] JSON issue in MarkLogic 7 To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> Message-ID: <dfdf2fd50bf5aa42adaf93ff2e3ca1850f9...@exchg10-be01.marklogic.com<mailto:dfdf2fd50bf5aa42adaf93ff2e3ca1850f9...@exchg10-be01.marklogic.com>> Content-Type: text/plain; charset="windows-1252" Hi, Gnana: This could be a bug, but it's hard to be sure without more detail. Would I be right in assuming that you have created a custom snippeting transform? v7 did include some work on snippeting for JSON. Can you provide specifics about the input to the transform, the transform code, and the output from the transform? Erik Hennum ________________________________ From: general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [general-boun...@developer.marklogic.com] on behalf of gnanaprakash.bodire...@cognizant.com<mailto:gnanaprakash.bodire...@cognizant.com> [gnanaprakash.bodire...@cognizant.com] Sent: Tuesday, November 26, 2013 2:04 AM To: general@developer.marklogic.com<mailto:general@developer.marklogic.com> Subject: [MarkLogic Dev General] JSON issue in MarkLogic 7 Hi I recently updated my MarkLogic server from v6 to v7 and I got an issue with json conversion. Details: MarkLogic 6: As part of REST-API, when we supply the parameter format=json, the entire response was getting converted into JSON irrespective of what we have in content node. i.e. By default we get search suggestions but I used transformation to get the full document and converted them to JSON which ensured I get results in JSON format. MarkLogic 7: We now additionally have mimetype and format in JSON response which I believe are coming from REST decorator. Even though when I supply format=json, the decorator is searching for document type and making it as xml format because of which raw content node is treated as string. Is there any way we can fix this or is this what we need to live with? Another question, My assumption is whenever REST API is updated, MarkLogic will use version numbers like /v1/, /v2/?/LATEST to ensure we are not losing the old REST API. Is this not available now? Gnana(GP) 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. 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.
_______________________________________________ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general