We mark xml elements as json:array=true to force serialization as array in JSON. However: when the element happens to be empty the JSON serialization fails and creates illegal output. If I omit the json:array marker, all is fine.
Consider this simple fragment:
xquery version "3.1";
declare option exist:serialize "method=json indent=yes media-type=application/json";
<addr xmlns:json="http://www.json.org">
<addrLine json:array="true"/>
<addrLine json:array="true"/>
</addr>
Yields
{ "addrLine" : [, ] }
Expected
{ "addrLine" : null }
To Reproduce
Run the fragment as above
Context (please always complete the following information):
wouldn't you expect the following?
{ "addrLine" : [null, null] }
@ahenket So this certainly is a bug, because { "addrLine" : [, ] } is not even valid JSON.
Do you expect
xquery version "3.1";
declare option exist:serialize "method=json indent=yes media-type=application/json";
<addr xmlns:json="http://www.json.org">
<addrLine json:array="true"/>
</addr>
to return { "addrLine" : [] } ?
I would expect the original XML-fragment to yield { "addrLine" : [null, null] } as @dizzzz already noted but in this case the second XML-fragment should also be { "addrLine" : [null] }.
Do we have a specification for this (exist specific) serialisation?
@line-o The most complete documentation on the eXist-specific JSON serializer (which preceded the XQuery 3.1 serialization spec) is this article: https://exist-db.org/exist/apps/wiki/blogs/eXist/JSONSerializer.
Most helpful comment
wouldn't you expect the following?