Java JSON Tutorial

JSON (JavaScript Object Notation), is a simple and easy to read and write data exchange format. It’s popular and implemented in countless projects worldwide, for those don’t like XML, JSON is a very good alternative solution.
In this series of Java JSON tutorials, we focus on three popular third party Java libraries to process JSON data, which are Jackson, Google Gson and JSON.simple
Jackson
A High-performance JSON processor.
- Jackson data binding example – Object & JSON
Example to use ObjectMapper writeValue() and readValue() to convert Java object to / from JSON. - Jackson data binding example – Map & JSON
Example to convert Java Map to / from JSON - Jackson Tree Model example
Read JSON into Tree, like DOM for XML. - Jackson Streaming example
Example to use JsonGenerator() and JsonParser() to stream read and write JSON data. - Pretty print JSON output in Jackson
Pretty print JSON output via defaultPrettyPrintingWriter().
Google Gson
It was originally created for use inside Google, now it is used by many public projects.
- Gson data model example – Object & JSON
Example to use toJson() and fromJson() to convert Java Object to / from JSON. - Gson Streaming example
Example to use JsonWriter() and JsonReader () to stream read and write JSON data. - Pretty print JSON output in Gson
Pretty print JSON output via GsonBuilder.
JSON.simple
Simple Java library for JSON, to read and write JSON data.
- JSON.simple example – Read and write JSON
Example to show you how to read and write JSON data to / from file.
References
- Introducing JSON
- JSON described in RFC 4627
- JSON Wiki
- Jackson official website
- Gson official website
- JSON.simple official website
- Review of 5 Java JSON libraries
- Jackson vs Gson

This code works fine for me
Where as if I change Media Type to JSON, it throws error -500.
16558 [http-8080-2] ERROR org.apache.wink.server.internal.handlers.FlushResultHandler – The system could not find a javax.ws.rs.ext.MessageBodyWriter or a DataSourceProvider class for the java.util.ArrayList type and application/json mediaType. Ensure that a javax.ws.rs.ext.MessageBodyWriter exists in the JAX-RS application for the type and media type specified.
Nice one
if the value has a double quotation(“), which function should I use?
thanks :)
You are just posting, we followed you, become victims while developing the applications.
We got the following error.If we would have followed,JDK JSON we might not face this problem…
I realized that this is not your mistake, Googles product bug…
Inconvenience regretted..
Laxman, he is only helping you and before posting any anything you should have been sure !
Thanks Mkyong… This site is really very useful for all the queries related to JSON..
ITS RIGHT THIS WEBSITE GOOD FOR JSON
Hi,
My doubt on struts2 jquery grid. I want to get the column names of a grid from struts2 Action class.
Please help me
how to get property names of Action class or DAO class.
based on the property names i generate grid dynamically.
Thank u…..
Really its a very good tutorial …… Thank you so much.
Thank you so much.
This tutorial is very useful with me.
very nice for understanding i never see like this before.
Implementing an interface means overiding its methods. So @overide was used.
we can not override abstract methods we can implement abstract methods.
you are a very good engineer.
Excellent , mkyong @ BEST . Really Appreciable .Tons of Best Wishes.
Thanks
Muskandaza