How to parse JSON in Java

In this Java tutorial, we are going to parse the JSON data using java program. To parse the JSON object we need to add some extra jar/library. In this example, I am using JSON.simple to parse the objects. You can do this by other API like Gson or Jackson 2.


Download the JSON.simple  jar or add the maven/gradle dependency in your project.

compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'

Check the full example
package org.websparrow;

import java.util.Iterator;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

public class JsonParseExample {
	public static void main(String[] args) {

		JSONParser jsonParser = new JSONParser();
		try {

			Object object = jsonParser.parse(new FileReader("data.json"));

			JSONObject jsonObject = (JSONObject) object;

			// System.out.println(jsonObject);

			long founded = (Long) jsonObject.get("founded");
			System.out.println("founded: " + founded);

			String location = (String) jsonObject.get("location");
			System.out.println("location: " + location);

			String name = (String) jsonObject.get("name");
			System.out.println("name: " + name);

			JSONArray articles = (JSONArray) jsonObject.get("articles");
			Iterator itr = articles.iterator();
			while (itr.hasNext()) {
				System.out.print(" " +;

		} catch (Exception e) {


founded: 2016
location: India
articles: java struts web

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.