Solved

Java code to convert JSON to XML

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

746 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

10 Experts available now in Live!

Get 1:1 Help Now