Skip to content

feat(xml-parser) Option for, do not unwrap single values. Keep arrays. #185

@Domvel

Description

@Domvel

fast-xml-parser parses the xml in an intelligent way. This is awesome. See these examples:


XML with multiple values:

<complies>
  <standard>STD1</standard>
  <standard>STD2</standard>
</complies>

in json:

{
    "complies": {
        "standard": [
            "STD1",
            "STD2"
        ]
    }
}

XML with single value:

<complies>
  <standard>STD1</standard>
</complies>

in json:

{
    "complies": {
        "standard": "STD1"
    }
}

My feature-request is to add an option to force keeping the array also for single values to normalize the whole xml. An option with the default value false to keep the current behavior as prefered behavior.

The new option could be named doNotUnwrapSingleValue or something like this. The export for single values in xml should result in this json:

{
    "complies": {
        "standard": ["STD1"]
    }
}

Why?
Because every node has the same structure.

Note:
This does not affect the root node. The root node never have multiple values. (tested in xml2js)

What do you think about my suggestion?

fast-xml-parser version: 3.12.20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions