-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Conversion from XML to JSON array inconsistency #30
Comments
This would force elements with single child nodes to always create arrays. I don't think we want this: {
root: [
{
child: [
{
grandchild: [
{
"text"
}
]
}
]
}
]
} Your expected output should also be: Expected:
{ "export": [{ "data": [{ "row": [{ "@id": "0", "TYPE": "X", "ID": "123" }] }] }] } as Is there a reason you want this feature, or is it just for consistency's sake? |
Encountering the same issue. It would be great to be able to pass a set of xpaths to the converter telling it: these nodes should be arrays. |
@IamRaduB If I am understanding this correctly, you want to be able to determine which element nodes should have their contents to be always grouped into an array. I am guessing you are post-processing the resulting JS object. Maybe it would be better to allow customizing the converter; so you can tweak the output as you require. Can you describe the use case a bit? |
I support this proposal, it very useful. It is convenient to get the expected result. |
For me it's about consistency. I retrieve XML data from a SOAP service. After converting to JSON, I process it. The code would be much simpler if I knew I'll always have an array where expected (array with 0,1 or more elements). |
I too bumped with this requirement @oozcitak. Maybe using the element custom parser to enforce array treatment for selected element names? 🤔 Otherwise in order to let the dev choose, the |
Describe the bug
Given XML with multiple rows:
produces JSON with row as array.
vs XML with a single row:
produced JSON with row not as an array.
To Reproduce
Expected behavior
Result:
{ "export": { "data": { "row": { "@id": "0", "TYPE": "X", "ID": "123" } } } }
Expected:
{ "export": { "data": { "row": [{ "@id": "0", "TYPE": "X", "ID": "123" }] } } }
Version:
The text was updated successfully, but these errors were encountered: