Exist: [BUG] JSON serialization for empty json:array

Created on 16 Aug 2021  路  4Comments  路  Source: eXist-db/exist

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):

  • macOS 11.5.2
  • eXist-db version: 5.3.0 stable
  • java version "15.0.2" 2021-01-19
bug

Most helpful comment

wouldn't you expect the following?

{ "addrLine" : [null, null] }

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

merenyics picture merenyics  路  3Comments

cmil picture cmil  路  3Comments

mathias-goebel picture mathias-goebel  路  6Comments

joewiz picture joewiz  路  3Comments

Bpolitycki picture Bpolitycki  路  4Comments