Click to See Complete Forum and Search --> : need xml -> json converter in java


andersod2
April 12th, 2010, 02:22 AM
Does anyone know of a good XML to JSON parser for Java? The one we are using now has an issue that I'm hoping is resolvable with a better parser. Basically, the issue is the parser doesn't know when the xml elements are referring to an array or not. So for example when we input the following xml everything is fine:


<outer>
<inner>
....
</inner>
<inner>
....
</inner>
</outer>



So it gives us JSON that is an outer object with an array of two inner objects. But if we input this:


<outer>
<inner>
....
</inner>
</outer>


...the inner is no longer an array because there's only one instance of it. This means our JSON parser now thinks inner is just an object and this messes up further parsing because we never know what type inner is....

Right now our only solution is an ugly conversion function that seems silly to me...any way around this with a better parser perhaps?