Javatpoint Logo

91-9990449935

 0120-4256464

Javatpoint Logo

Java JSON

The json.simple library allows us to read and write JSON data in Java. In other words, we can encode and decode JSON object in java using json.simple library.

The org.json.simple package contains important classes for JSON API.

  • JSONValue
  • JSONObject
  • JSONArray
  • JsonString
  • JsonNumber

Install json.simple

To install json.simple, you need to set classpath of json-simple.jar or add the Maven dependency.

1) Download json-simple.jar, Or

2) To add maven dependency, write the following code in pom.xml file.

1) Java JSON Encode

Let's see a simple example to encode JSON object in java.

Output:

{"name":"sonoo","salary":600000.0,"age":27}

Java JSON Encode using Map

Let's see a simple example to encode JSON object using map in java.

Output:

{"name":"sonoo","salary":600000.0,"age":27}

Java JSON Array Encode

Let's see a simple example to encode JSON array in java.

Output:

["sonoo",27,600000.0]

Java JSON Array Encode using List

Let's see a simple example to encode JSON array using List in java.

Output:

["sonoo",27,600000.0]

2) Java JSON Decode

Let's see a simple example to decode JSON string in java.

Output:

sonoo 600000.0 27
Next TopicAJAX JSON Example




Latest 4 Tutorials on JavaTpoint