Search code examples
xquerymarklogicmarklogic-10

Convert the JSON attribute from smallcase to uppercase in XQuery and Marklogic 10


I have loaded the below JSON in MarkLogic and I need to convert the Name property value to upper case:

{ "Name": "User", "Id": "1", "date": "2022-01-01" }

Any way to convert the value to upper case in Marklogic and XQuery, looking like below format?

{ "Name": "USER", "Id": "1", "date": "2022-01-01" }

Solution

  • One way would be to select the Name, use upper-case() and create a text() node, and then use xdmp:node-replace().

    Assuming that you have the document assigned to a variable $doc:

    let $name := $doc/Name
    return xdmp:node-replace($name, text {upper-case($name) } )
    

    For reference, there are a few examples in the documentation of updating different types of properties: https://docs.marklogic.com/guide/app-dev/json#id_60123