How to search json document using xquery and output results

Issues related to W3C XQuery.
vkdev
Posts: 21

How to search json document using xquery and output results

Tue Feb 07, 2017 7:59 pm

Hi
If I use this xquery against json document-
let $x:=cts:search(fn:doc()/colData, cts:json-property-value-query("taskData", "id"))
I don't get any output.
Is it a transformation issue? Which transformation scenario do I select/configure to work with json document and see the output??

The same query produces json output correctly in marklogic query console.
alex_jitianu
Posts: 600

Re: How to search json document using xquery and output results

Tue Feb 14, 2017 5:06 pm

Hi,

To execute this inside Oxygen there are two possibilities:
1. Use the XPath/XQuery Builder. On the top of the view select the MarkLogic connection as the engine that will execute the queries. paste the query and execute it.
2. If you put the query inside an XQuery editor then you need to create a transformation scenario for it and, again, select the MarkLogic connection as the engine.

If it still doesn't work then perhaps the qconsole executes the query on a different database than Oxygen? I tried something similar and in my case the query returned the expected result. How I tested:
1. I've loaded inside the data base the JSON:

Code: Select all

{"personnel": {"person": [
    {
        "id": "Big.Boss",
        "name": {
            "family": "Boss",
            "given": "Big"
        },
        "email": "chief@oxygenxml.com",
        "link": {"subordinates": "one.worker two.worker three.worker four.worker five.worker"}
    }
]}}

2. In the XQuery/XPath builder I've executed:

Code: Select all

let $x:=cts:search(fn:doc()/personnel, cts:json-property-value-query("id", "Big.Boss"))

return $x


Best regards,
Alex
vkdev
Posts: 21

Re: How to search json document using xquery and output results

Fri Feb 24, 2017 9:18 pm

Alex
Please provide some details about configuring a transformation for json. What "Type"? I don't see Json transformation with XQuery. There is XML transformation with XQuery but that does not work.
alex_jitianu
Posts: 600

Re: How to search json document using xquery and output results

Mon Feb 27, 2017 5:44 pm

Hi,

Oxygen doesn't have a built-in engine for processing Json with XQuery. If the JSON is stored inside MarkLogic then you can create an XQuery, run it against the server and, in the context of the server, that query can process JSON. On the Oxygen side, you will create an XQuery transformation and in the scenario you will select the MarkLogic connection as the Engine.

Best regards,
Alex

Return to “XQuery”

Who is online

Users browsing this forum: No registered users and 0 guests