How can we read a JSON object in a JSP, Servlet or in any other Java program?

  • can we use gson object for this? – Sadesh Kumar N Nov 25 '09 at 16:13

I would recommend using Gson for this. It has the advantage that it supports generics very well and it is also performant. I've posted a Gson#fromJson() example before here: Converting JSON to Java


With the json library, there is a JAR of it located here. Also, based upon this answer, you might want to look at JSON-lib


JSON.org has a lot of good information on reading JSON in Java (and other languages as well). They provide a good reference implementation that many other libraries use.

  • That's a good page -- not sure the ref impl is all that great (almost all alternatives from the page are better IMO), but it's good it has been available for years now, and has encourages others to implement better alternatives. :-) – StaxMan Nov 26 '09 at 6:24

Take a look at Jackson.


Using a library such as the one described at: http://www.json.org/java/

Looking at the description of gson, it certainly looks like it would do the job as well.
