Main Tutorials

Java JSON Tutorials

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
29 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Bhagavan
11 years ago

Nice one

hamid mohammadi
4 years ago

hi
in “Gson” there is a word that is not correct . misspell

Sujata Sid
10 years ago

It’s Really Helpfull Tutorial!!!!!!!!!!!

vishal
10 months ago

how to convert excel format to jason and parse json data to the given word format using spring

khushal jain
4 years ago

want to parse this json data using java, want to know source code

{“data”:[{“header”:”center:@:ENVELOP_ID:@:center_city:@:dispatch_date”},{“value”:”:@::@::@:”},{“value”:”[[HEADERTITLE]] e 101 achla”},{“value”:”:@::@::@:”},{“value”:”101:@:14:@:City 1:@:05/07/2019″},{“value”:”:@:15:@:City 1:@:05/07/2019″},{“value”:”:@:16:@:City 1:@:05/07/2019″},{“value”:”:@:17:@:City 1:@:05/07/2019″},{“value”:”:@:18:@:City 1:@:05/07/2019″},{“value”:”:@:19:@:City 1:@:05/07/2019″},{“value”:”:@:20:@:City 1:@:05/07/2019″},{“value”:”:@:21:@:City 1:@:05/07/2019″},{“value”:”:@:22:@:City 1:@:05/07/2019″},{“value”:”:@:23:@:City 1:@:05/07/2019″},{“value”:”:@::@::@:”},{“value”:”[[HEADERTITLE]] h 102 aahl”},{“value”:”:@::@::@:”},{“value”:”102:@:16:@:City 2:@:06/07/2019″},{“value”:”:@:17:@:City 2:@:06/07/2019″},{“value”:”:@:18:@:City 2:@:06/07/2019″},{“value”:”:@:19:@:City 2:@:06/07/2019″},{“value”:”:@:20:@:City 2:@:06/07/2019″},{“value”:”:@:21:@:City 2:@:06/07/2019″},{“value”:”:@:22:@:City 2:@:06/07/2019″},{“value”:”:@:23:@:City 2:@:06/07/2019″},{“value”:”:@:24:@:City 2:@:06/07/2019″},{“value”:”:@::@::@:”},{“value”:”[[HEADERTITLE]] c 103 bbgv “},{“value”:”:@::@::@:”},{“value”:”103:@:12:@:City 3:@:07/07/2019″},{“value”:”:@:13:@:City 3:@:07/07/2019″},{“value”:”:@:14:@:City 3:@:07/07/2019″},{“value”:”:@:15:@:City 3:@:07/07/2019″},{“value”:”:@:16:@:City 3:@:07/07/2019″},{“value”:”:@:17:@:City 3:@:07/07/2019″},{“value”:”:@:18:@:City 3:@:07/07/2019″},{“value”:”:@:19:@:City 3:@:07/07/2019″},{“value”:”:@::@::@:”},{“value”:”[[HEADERTITLE]] s 104 eedg “},{“value”:”:@::@::@:”},{“value”:”104:@:99:@:City 4:@:08/07/2019″},{“value”:”:@:100:@:City 4:@:08/07/2019″},{“value”:”:@:101:@:City 4:@:08/07/2019″},{“value”:”:@:102:@:City 4:@:08/07/2019″},{“value”:”:@:103:@:City 4:@:08/07/2019″},{“value”:”:@:104:@:City 4:@:08/07/2019″},{“value”:”:@:105:@:City 4:@:08/07/2019″},{“value”:”:@::@::@:”},{“value”:”[[HEADERTITLE]] p 105 ffgb”},{“value”:”:@::@::@:”},{“value”:”105:@:77:@:City 5:@:09/07/2019″},{“value”:”:@:78:@:City 5:@:09/07/2019″},{“value”:”:@:79:@:City 5:@:09/07/2019″},{“value”:”:@:80:@:City 5:@:09/07/2019″},{“value”:”:@:81:@:City 5:@:09/07/2019″},{“value”:”:@:82:@:City 5:@:09/07/2019″}],”status”:”success”}

Pilar
5 years ago

Great job! Mkyong, could you help with Java Persistent APIs examples, Please.

neelesh
8 years ago

Great tutorial. Thanks.

Sandeep Andhale
8 years ago

mostly where we use JSON

jaychang
9 years ago

FastJSON https://github.com/alibaba/fastjson
It’s really very fast

Jesse Bowes
9 years ago

There’s also a tool that can take JSON as input and generate Java classes from it (both source and compiled). It can also add Jackson bindings during generation.

http://javafromjson.dashingrocket.com

jessebs
10 years ago

http://javafromjson.dashingrocket.com/ can generate the Java Classes from JSON so you don’t have to write them yourself

Vishal
10 years ago

To develop a webservice using java to fetch the data from json array and store that data on the database…

nirmal
10 years ago
Rituranjan
10 years ago
Anuj
10 years ago

This code works fine for me

@GET
	@Produces("application/xml")
	public Response getList() {
		List<Person> personArray = new ArrayList<Person>();
		Person p1 = new Person();
		p1.setName("First Person");
		p1.setId(1);
		p1.setGender("M");
		Person p2 = new Person();
		p2.setName("Second Person");
		p2.setId(2);
		p2.setGender("M");
		Person p3 = new Person();
		p3.setName("Third Person");
		p3.setId(3);
		p3.setGender("M");
		personArray.add(p1);
		personArray.add(p2);
		personArray.add(p3);
		@SuppressWarnings("rawtypes")
		GenericEntity entity = new GenericEntity<List<Person>>(personArray){};
		return Response.ok(entity).build();
	}

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.

felix
11 years ago

if the value has a double quotation(“), which function should I use?
thanks 🙂

Laxman Chowdary
11 years ago

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…

com.google.gson.CircularReferenceException: circular reference error
	at com.google.gson.JsonSerializationVisitor.start(JsonSerializationVisitor.java:61)
	at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:109)
	at com.google.gson.JsonSerializationVisitor.getJsonElementForChild(JsonSerializationVisitor.java:147)
	at com.google.gson.JsonSerializationVisitor.addAsChildOfObject(JsonSerializationVisitor.java:127)
	at com.google.gson.JsonSerializationVisitor.visitObjectField(JsonSerializationVisitor.java:114)
	at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:69)
	at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
Laxman Chowdary
11 years ago

I realized that this is not your mistake, Googles product bug…
Inconvenience regretted..

Sara Ali
11 years ago

Laxman, he is only helping you and before posting any anything you should have been sure !

jyothsana
11 years ago

Thanks Mkyong… This site is really very useful for all the queries related to JSON..

Shubhrajyoti satpathy
11 years ago
Reply to  jyothsana

ITS RIGHT THIS WEBSITE GOOD FOR JSON

sagar srinivas
11 years ago

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…..

Bhaskar Reddy
11 years ago

Really its a very good tutorial …… Thank you so much.

tttrung43
12 years ago

Thank you so much.
This tutorial is very useful with me.

rojer
12 years ago

very nice for understanding i never see like this before.

Sylar
12 years ago

Implementing an interface means overiding its methods. So @overide was used.

chandan singh
10 years ago
Reply to  Sylar

we can not override abstract methods we can implement abstract methods.

????
12 years ago

you are a very good engineer.

Muskandaza
12 years ago

Excellent , mkyong @ BEST . Really Appreciable .Tons of Best Wishes.

Thanks
Muskandaza