[MarkLogic Dev General] Transform response to camel case json

jaydip rananavare jaydiprananavare at gmail.com
Tue Mar 3 22:19:52 PST 2015


Hi All,

I am trying to convert query response to camel case json.
So I added custom configuration with option camel-case as true but
json:transform-to-json-object function returns json without camel case when
element name
1. contain '_' (e.g PUBLISH_DATE)
2. is in uppercase it does not convert it to lower case
3. contain '-' (e.g ONE-MORE-ELEMENT) it does not convert first word to
lower case (ONEMoreElement)


Here is my query and output

xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import module namespace json = "http://marklogic.com/xdmp/json" at
"/MarkLogic/json/json.xqy";

let $x := xdmp:set-response-content-type("application/json")
let $custom :=
    let $config := json:config("custom")
    let $_ := map:put($config, "camel-case", fn:true())
    return $config

let $xml :=
    <BOOK>
        <AUTHOR>Gambardella, Matthew</AUTHOR>
        <TITLE>XML Developer's Guide</TITLE>
        <GENRE>Computer</GENRE>
        <PRICE>44.95</PRICE>
        <PUBLISH_DATE>2000-10-01</PUBLISH_DATE>
        <DESCRIPTION>An in-depth look at creating applications with
XML.</DESCRIPTION>
        <ONE-MORE-ELEMENT>some value</ONE-MORE-ELEMENT>
    </BOOK>

return json:transform-to-json-object($xml, $custom)


output :-

{
    "BOOK": {
        "AUTHOR": "Gambardella, Matthew",
        "TITLE": "XML Developer's Guide",
        "GENRE": "Computer",
        "PRICE": "44.95",
        "PUBLISH_DATE": "2000-10-01",
        "DESCRIPTION": "An in-depth look at creating applications with
XML.",
        "ONEMoreElement": "some value"
    }
}


-- 

Cheers,

*Jaydip*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150304/0bf756a9/attachment.html 


More information about the General mailing list