[xquery-talk] MarkLogic using JSONiq for processing JSON ?

Michael Kay mike at saxonica.com
Fri May 8 04:09:05 PDT 2015

> So, to me,  the decisions of the W3C working group seems random, and rather based on a two years old
> ……...rather then justified by any technical reasons.

No, all the arguments were all technical. For example:

* generalizing maps to allow any atomic type as the key, rather than only a string, was because of specific use cases that required this (remember that the first proposal to add maps to XDM came from XSLT streaming work, not from JSONiq)

* the decision to use “map{…}” rather than “{…}” was to some extent subjective, but was motivated by technical arguments such as the ability to produce good error messages, retaining options for future extensions to the grammar, etc. Expressions beginning with “{“ are particularly problematic because “{“ is used to delimit embedded expressions in element content, and “{{“ is used to escape “{“ as an ordinary character; they are also very obscure when used as the body of a function (declare function f {{1:2}}). Before making this decision, we looked at how many other popular languages solve this problem.

* the decision to allow any sequence to act as a member of an array enabled things like the fn:apply() function, whose second argument is an array of arbitrary sequences; it also enabled JSON null to be represented by an empty sequence, which avoided the need for pervasive changes to the language to define how every function and operator should handle a JSON null. Reducing the number of concepts by one is a definite plus.

Getting agreement on all these points was a very lengthy process with much heated argument. Although the decisions made were not always the ones I personally advocated, I think the final language works well. If there’s one aspect I’m still a little unhappy about, it’s the fact that an array behaves like a single item, so for example

let $A := [1,2,3]
return $A[1]

returns [1,2,3]

But that’s there because we tried very hard to find a way to avoid this surprise, and failed: the sequence=item model in XDM is just too deeply embedded.

Michael Kay

More information about the talk mailing list