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
Convert xml to json #305
Comments
You may made back conversion json to xml. The service here https://javadev.github.io/xml-to-json/ |
Hi Sir, Thanks for prompt response. I won't convert back json to xml. I will convert the xml response to json and send it back to client. please let me know is there any way to achieve the expected json result (mentioned in my previous comment) by skipping the XML root element and also the attribute values? |
To get json {
"b": [
{
"c": "10020",
"d": "NEWYORK",
"e": "NY"
},
{
"c": "06373",
"d": "OLDLYME",
"e": "CT"
}
]
} you need this XML <?xml version="1.0" encoding="UTF-8"?>
<root>
<b>
<c>10020</c>
<d>NEWYORK</d>
<e>NY</e>
</b>
<b>
<c>06373</c>
<d>OLDLYME</d>
<e>CT</e>
</b>
</root> |
This XML <a>
<b ID="0">
<c>10020</c>
<d>NEWYORK</d>
<e>NY</e>
</b>
<b ID="1">
<c>06373</c>
<d>OLDLYME</d>
<e>CT</e>
</b>
</a> will be converted to this json {
"a": {
"b": [
{
"-ID": "0",
"c": "10020",
"d": "NEWYORK",
"e": "NY"
},
{
"-ID": "1",
"c": "06373",
"d": "OLDLYME",
"e": "CT"
}
]
},
"#omit-xml-declaration": "yes"
} |
Thanks sir for spending yours valuable time and let me check whether i could use the xml to json conversion as it is. |
I may add a new mode to the xmlToJson method REMOVE_FIRST_LEVEL_XML_TO_JSON. Will it be good for you? |
Yes sir, it will be really helpful for me. Sir, also please let me know how long this change will take time to complete ? |
Implemented #307 |
The new version was released today. 🎉 |
I am getting the API response as following XML,
<a> <b ID="0"> <c>10020</c> <d>NEWYORK</d> <e>NY</e> </b> <b ID="1"> <c>06373</c> <d>OLDLYME</d> <e>CT</e> </b> </a>
I want to convert the above xml to json as follows,
{ "b": [ { "c": "10020", "d": "NEWYORK", "e": "NY" }, { "c": "06373", "d": "OLDLYME", "e": "CT" } ] }
I have already tried U.xmlToJson(), U.fromXmlWithoutAttributes() but unable to achieve the above expected result.(Skip the root element
<a>
and also skip xml element attributes("ID") ). Please let me know will this achieved by using Underscore-lib?The text was updated successfully, but these errors were encountered: