Solved

Java code to convert JSON to XML

Posted on 2009-05-11
5
4,647 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Animated .jpg? 13 61
Google Sheets Script 21 58
Check if Object property exists? 3 19
How can I started with all items collapsed when using Nested Sortable ? 4 21
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'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now