Index ¦ Archives ¦ Atom

MarkLogic xdmp:to-json()

I do like that MarkLogic has a to-json function and that I don't need to download third-party code to make something like JSON work, especially in 2010, years after JSON has become a fairly well known standard.

One problem I ran into was that when a sequence is converted to JSON, a JSON array is returned.

('a', 'b', 'c', 'd')

becomes

['a', 'b', 'c', 'd']

The problem comes when only one value is returned in a sequence, such as ('a'). This now becomes the string 'a' as JSON instead of being a javascript array. I can understand why, but I wanted an array since the autocomplete jQuery UI plugin always uses a javascript array. So, in my code I now check for a sequence of one and concatenate '[' to the beginning and ']' to the end to give me a valid JSON array.

If I could have, I would have changed the autocomplete plugin to accept a string JSON parameter as well and then the MarkLogic code would have worked fine.

© Steve Spigarelli. Built using Pelican. Theme by Giulio Fidente on github.