Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java code to convert JSON to XML

Posted on 2009-05-11
5
Medium Priority
?
4,715 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 200 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 300 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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

670 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