• Post Reply Bookmark Topic Watch Topic
  • New Topic

Best Way to convert JSON to XML  RSS feed

 
Durga Roobini
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please anyone tell me the best and efficient way to convert JSON to XML in JAVA,because my json data will come from n number of third party servers,so i have to convert that JSON data to XML data in JAVA,i use XMLSerializer and JSONSerializer and also tried org.json library,few json data cannot convert into xml it shows error like "XML document must have a top level element. Error processing resource","Invalid character in text content","WhiteSpace character not allowed" etc.., and also JSON data with array bracket,this kind of data means how to handle? i tried JSONArray for this types but no results,anyone show me the way please
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's start by you telling us why you want to do this. JSON is generally a useful data format; what's the point of converting it to XML?

It would also be useful to see the code you have so far, if you really want to do this.
 
Durga Roobini
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because i have to send standard output to my phonegap client ,i receive xml and soap response from various third party server,so i recieve json means i have to convert it,here only am strucking,as above i mention my problem,moreover my project flow going on like that only so surely i need solution for this problem please help me
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None of this explains why you think JSON is a better format than XML; it likely isn't.

As to finding a solution, please re-read the last sentence of my previous post.
 
Durga Roobini
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my project rule and flow like that sir please provide solution
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my project rule and flow like that

OK, you don't want to talk about the design choices you've made, and you don't want to learn about different -possibly better- approaches. Fine.

please provide solution

I'll say it for a third time, but I won't say it a fourth time:
Ulf Dittmer wrote:It would also be useful to see the code you have so far
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The common tool people use is JSONObject available at the JSON.org website L http://www.json.org/java/index.html

What Ulf is trying to get you to do is explain a little about what you are wanting to do in terms of the project requirements. This will help you receive better advice from some people who tend to be purists in how they approach problem solving (nothing wrong with that). What some people don't understand is why you have this requirement. Others , OTOH , can understand the necessity of converting between two data formats because it is a common daily requirement when performing system integration tasks.

While you can use the two functions found at http://www.json.org/java/index.html ( JSONobject(string) and XML.toString(json) ) to perform adequate or rudimentary conversion that may work much of the time , you may find it necessary to use a more robust solution ( IBM Integration Bus ) to more fully and sucessfully convert every JSON payload to XML. IBM Integration Bus is available to developers as a free download.

The reason you may need a more robust solution is because there is alot more to integrating JSON payloads into your solution than just the data format.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!