Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Domvel opened this issue Sep 2, 2019 · 2 comments
Closed

Comments

@Domvel
Copy link

Domvel commented Sep 2, 2019

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

@Domvel Domvel changed the title feat(xml-parser) Option for "Do not reduce values. Keep arrays." feat(xml-parser) Option for, do not unwrap single values. Keep arrays. Sep 2, 2019
@Domvel
Copy link
Author

Domvel commented Sep 2, 2019

I close it, because it's not important at this moment. I like the current behavior. And it will come to late. I have to adapt it to the last xml-parsers behavior. (xml2js)
But feel free to re-open this issue if you want this feature.

@Domvel Domvel closed this as completed Sep 2, 2019
@amitguptagwl
Copy link
Member

I believe its a good idea. Need to cross validate it against previously raised requirements

#181 #135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants