5

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

Radiodef
  • 37,180
  • 14
  • 90
  • 125
Sadesh Kumar N
  • 1,962
  • 7
  • 19
  • 26

5 Answers5

6

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

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
5

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

Community
  • 1
  • 1
John Paulett
  • 15,596
  • 4
  • 45
  • 38
3

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.

Kevin
  • 30,111
  • 9
  • 76
  • 83
  • 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 06:24
3

Take a look at Jackson.

Jim Ferrans
  • 30,582
  • 12
  • 56
  • 83
2

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.

Andy
  • 8,870
  • 1
  • 31
  • 39