Oh thank you - now I understand.Of course, you needed a rule to represent zero-length string names, and "_" was the almost obvious choice!

Sorry for the disturbance -
Hans-Jürgen



Christian Grün <christian.gruen@gmail.com> schrieb am 14:27 Mittwoch, 30.September 2015:


Hi Hans-Jürgen,

You may be surprised, but the behavior is correct. It's defined in the
conversion rules in our documentation [1]: "
Empty names are represented by a single underscore (_).". The
following example illustrates the behavior:

  json:parse('{ "":"" }')

Hope this helps,
Christian

[1] http://docs.basex.org/wiki/Json_Module#Direct


On Wed, Sep 30, 2015 at 2:22 PM, Hans-Juergen Rennau <hrennau@yahoo.de> wrote:
> Dear BaseX,
>
> I think there is a very slight bug in the JSON serializer: when an element
> with type="object" has a <_> child, I think the serializer should report an
> error (as underscores must be doubled, if not using the name "_", reserved
> for array items. Instead, the serializer creates a property with the empty
> string as name. Example:
>
> json:serialize(
> <json type="object">
>  <BaseX type="object">
>    <_>is phantastic</_>
>  </BaseX>
> </json>
> )
> =>
> {
>  "BaseX":{
>    "":"is phantastic"
>  }
> }
>
> Compare with:
>
> json:serialize(
> <json type="object">
>  <BaseX type="object">
>    <__>is phantastic</__>
>  </BaseX>
> </json>
> )
> =>
> {
>  "BaseX":{
>    "_":"is phantastic"
>  }
> }
>
> It may look like pedantry, but this misbehaviour may cause confusion, as it
> is of course an interesting practise to create JSON by creating the XML
> format and in the end serializing: if then inspecting the end result, it is
> not immediately clear that the "":... is caused by the serializer, rather
> than by own code.
>
> Kind regards,
> Hans-Jürgen