Is there straightforward XQuery in Marklogic that produces JSON output out of simple XML sequence to be used with JQuery autocompete Is there straightforward XQuery in Marklogic that produces JSON output out of simple XML sequence to be used with JQuery autocompete json json

Is there straightforward XQuery in Marklogic that produces JSON output out of simple XML sequence to be used with JQuery autocompete


How about:

xquery version "1.0-ml";let $ids := <ids>  <id>Bank ATM</id>  <id>PostageShipping</id>  <id>WebHosting</id>  <id>ClientParking</id></ids>return xdmp:to-json(fn:data($ids/id))==>["Bank ATM", "PostageShipping", "WebHosting", "ClientParking"]

You may want to loop through your collection with a FLWOR, and replace <ids> in the example above with your <ex:Expense>


Good to see that you found a solution, but figured I'd pass along some additional info that would allow you to use the mljson library if you'd like.

The primary goal of the mljson library is to turn MarkLogic into a server for storing and searching over JSON. That said, it can be used to generate JSON via XQuery. However, because the library is built to consume the XML that the library itself generates, it requires the XML to be in a specific format in order to convert it to JSON. To generate your array, here's what the XML would need to look like:

<json type="array">    <item>Bank ATM</item>    <item>PostageShipping</item>    <item>WebHosting</item>    <item>ClientParking</item></json>

You'd just pass that XML to the json:xmlToJSON() function and out comes your JSON array.

As for the other JSON library that you found (the one under commons), it's not quite as flexible and doesn't fit your needs as well (although it is a bit more forgiving with it's input format).