Reputation: 19
The output of the following XML:
<users>
<user>
<id:name>Shikhar</id:name>
<id:age>31</id:age>
</user>
<user>
<xd:name>Shashank</xd:name>
<xd:age>29</xd:age>
</user>
</users>
should not have the id: or xd: in it.
{
"user": [
{
"name": "Shikhar",
"age": 31
},
{
"name": "Shashank",
"age": 29
}
]
}
I know how to convert from XML to XML and then to JSON. But I want a direct conversion.
Upvotes: 1
Views: 789
Reputation: 163352
Off-the-shelf programs to convert XML to JSON almost invariably produce something that isn't quite the JSON you want. That's because you know more about the semantics of the data than the general-purpose program does. Some of the utilities are more customizable than others, but none is perfect.
I think for most real-life conversions you should expect to do some tweaking either of the XML pre-transformation, or of the JSON post-transformation. Tweaking the XML is probably easier because there's nothing quite as powerful as XSLT on the JSON side.
Upvotes: 1