You may be surprised, but the behavior is correct. It's defined in the
Empty names are represented by a single underscore (_).". The
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