Solved

Java code to convert JSON to XML

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

832 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