Java JSON Example

In this tutorial you will learn about Java JSON example.

What is JSON?

  • JSON stands for JavaScript Object Notation.
  • JSON is a lightweight and an easier way for exchanging data on the web.
  • JSON is originated from JavaScript programming language.
  • JSON is a good alternative of XML.
  • JSON is language independent and supports data structures like object and array.

Java JSON Example

 

Java JSON Example

To use JSON with Java we require a library called as json.simple. You can download it from below link.

Download: http://www.javatpoint.com/jsonpages/json-simple-1.1.1.jar

After downloading it you need to import it to the IDE (NetBeans, Eclipse, etc) you are using. 

 

Encode and Decode JSON object in Java

JSON object contains data in the form of key and value pair. A JSON object example is given below.

 

An example to encode and decode JSON object in Java is given below.

 

Output

Neeraj Mishra
21

 

Encode and Decode JSON Array in Java

A JSON array example is given below.

 

An example to encode and decode JSON array in Java is given below.

 

Output

C
C++
Java
Python

 

Encode and Decode JSON Array of Objects in Java

A JSON array of objects example is given below.

 

An example to encode and decode JSON array of objects in Java is given below.

 

Output

C
C++
Java

 

Decode JSON String in Java

We can decode JSON string in following way.

 

Output

{“name”:”Neeraj Mishra”}
[“C”,”C++”,”Java”]

 

The above Java JSON example is self explanatory, still if you are unable to understand then feel free to ask by commenting below.

Leave a Comment

Your email address will not be published. Required fields are marked *