Solved

Java code to convert JSON to XML

Posted on 2009-05-11
5
4,697 Views
Last Modified: 2013-11-08
I am looking for Java code that I can use (i.e. open source) to convert a JSON string into XML.

I don't care so much about having a lot of control on how the conversion is done, as once I have XML, I can easily transform it with XSLT.

Any recommendation?
0
Comment
Question by:avernet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 39

Assisted Solution

by:abel
abel earned 50 total points
ID: 24352196
Here's one possibility: http://www.p6r.com/articles/2008/05/06/xslt-and-xpath-for-json/

But this is perhaps simpler: http://www.virtual-tech.net/resources/json2xml.html. It contains a small JavaScript snippet (yes, I know you use Java), that shows how to parse the JSON code into XML. See the source of that page (the popup shows only the output).
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 75 total points
ID: 24352250
http://jettison.codehaus.org/
http://xstream.codehaus.org/index.html

If you need I also have references for JavaScript or XSLT2 libraries that do that
0
 
LVL 1

Author Comment

by:avernet
ID: 24357082
@abel, thank you for responding. I have been looking at the two links you mentioned:

1) http://www.p6r.com/articles/2008/05/06/xslt-and-xpath-for-json/

The P6R code in C++ , so that won't work for me, but maybe other people reading this will find it useful.

2) http://www.virtual-tech.net/resources/json2xml.html

This is some very simple (= good!) code that uses Prototype. I don't fancy Prototype, but maybe will run with the idea. (I would have preferred a more robust, server-side solution to this.)
0
 
LVL 39

Expert Comment

by:abel
ID: 24357107
> I would have preferred a more robust, server-side solution to this

basically, the reason I mentioned, is that the same technique could be applied using java (or c# or whatever) on the server side. The simplicity was chosen because it makes it easier to adopt it for yourself, at least, that was the intention :)
0
 
LVL 1

Author Comment

by:avernet
ID: 24357122
@Gertone,Jettison seems the way to go. Also see this example from the XStream FAQ:

http://xstream.codehaus.org/faq.html#JSON

I will some experiments with this, and will report on it.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question