Skip to content

IsArray option isn't parsing tags with 0 as value correctly #490

@DolarJoe

Description

@DolarJoe
  • Are you running the latest version?
    "fast-xml-parser": "^4.0.9"
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?
    It seems to be broken

Description

I'd like to use IsArray option, however, it seems to break on tags which have value 0 inside of them, such as 0 or 0.0. It is inconsistent with other numbers, interger or floats, that have non 0 value, as shown in my provided example.

Input

<root>
    <a>0.00</a>
    <b>0.01</b>
</root>

Code

const parser = new XMLParser({isArray: (name, jpath, isLeaf, isAttr) => !isLeaf});
let result = parser.parse(fr.result);
console.log(JSON.stringify(result, undefined, 2))

Output

{
  "root": [
    {
      "a": [
        0
      ],
      "b": 0.01
    }
  ]
}

expected data

{
  "root": [
    {
      "a": 0,
      "b": 0.01
    }
  ]
}

Would you like to work on this issue?

  • Yes
  • No

Metadata

Metadata

Assignees

No one assigned

    Labels

    PendingPending to be confirmed by user/author for some check/update/implementationgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions