The org.json library is easy to use.

Just remember (while casting or using methods like getJSONObject and getJSONArray) that in JSON notation

  • [ … ] represents an array, so library will parse it to JSONArray
  • { … } represents an object, so library will parse it to JSONObject

Example code below:

import org.json.*;

String jsonString = ... ; //assign your JSON String here
JSONObject obj = new JSONObject(jsonString);
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts"); // notice that `"posts": [...]`
for (int i = 0; i < arr.length(); i++)
{
    String post_id = arr.getJSONObject(i).getString("post_id");
    ......
}

You may find more examples from: Parse JSON in Java

Downloadable jar: http://mvnrepository.com/artifact/org.json/json

Answer from user1931858 on Stack Overflow
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › stream › JsonParser.html
JsonParser (Java(TM) EE 7 Specification APIs)
Provides forward, read-only access to JSON data in a streaming way. This is the most efficient way for reading JSON data. The class Json contains methods to create parsers from input sources (InputStream and Reader).
Top answer
1 of 16
962

The org.json library is easy to use.

Just remember (while casting or using methods like getJSONObject and getJSONArray) that in JSON notation

  • [ … ] represents an array, so library will parse it to JSONArray
  • { … } represents an object, so library will parse it to JSONObject

Example code below:

import org.json.*;

String jsonString = ... ; //assign your JSON String here
JSONObject obj = new JSONObject(jsonString);
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts"); // notice that `"posts": [...]`
for (int i = 0; i < arr.length(); i++)
{
    String post_id = arr.getJSONObject(i).getString("post_id");
    ......
}

You may find more examples from: Parse JSON in Java

Downloadable jar: http://mvnrepository.com/artifact/org.json/json

2 of 16
714

For the sake of the example lets assume you have a class Person with just a name.

private class Person {
    public String name;

    public Person(String name) {
        this.name = name;
    }
}

Jackson (Maven)

My personal favourite and probably the most widely used.

ObjectMapper mapper = new ObjectMapper();

// De-serialize to an object
Person user = mapper.readValue("{\"name\": \"John\"}", Person.class);
System.out.println(user.name); //John

// Read a single attribute
JsonNode nameNode = mapper.readTree("{\"name\": \"John\"}");
System.out.println(nameNode.get("name").asText());

Google GSON (Maven)

Gson g = new Gson();

// De-serialize to an object
Person person = g.fromJson("{\"name\": \"John\"}", Person.class);
System.out.println(person.name); //John

// Read a single attribute
JsonObject jsonObject = new JsonParser().parseString("{\"name\": \"John\"}").getAsJsonObject();
System.out.println(jsonObject.get("name").getAsString()); //John

Org.JSON (Maven)

This suggestion is listed here simply because it appears to be quite popular due to stackoverflow reference to it. I would not recommend using it as it is more a proof-of-concept project than an actual library.

JSONObject obj = new JSONObject("{\"name\": \"John\"}");

System.out.println(obj.getString("name")); //John
Discussions

Best Java JSON Parser: Gson or Jackson?

Jackson, but mostly because I tend to use it from Spring MVC and it just works without any extra effort.

More on reddit.com
🌐 r/java
61
47
February 28, 2014
How can I parse JSON in Java? - LambdaTest Community
How can I parse JSON in Java? I have the following JSON text. How can I parse it to get the values of pageName, pagePic, post_id, etc.? { "pageInfo": { "pageName": "abc", "pagePic": "http://example.com/content.jpg" }, "posts": [ { "post_id": "123456789012_123456789012", "actor_id": "1234567890", ... More on community.lambdatest.com
🌐 community.lambdatest.com
1
April 2, 2024
How to parse Json with Java.

Google's GSON is great. Create the class structure, deserialize from json into java objects. Couldn't be simpler!

More on reddit.com
🌐 r/java
30
9
June 2, 2010
Parsing JSON object using Java
Unless this is an exercise to use a lower level library like org.json, I would strongly recommend using something that helps with the mapping to Java like Jackson instead More on reddit.com
🌐 r/javahelp
11
1
November 13, 2021
🌐
Medium
medium.com › @AlexanderObregon › javas-jsonparser-parse-method-explained-76b126f6110e
Java’s JsonParser.parse() Method Explained | Medium
October 13, 2024 - The JsonParser class in Java, part of the javax.json package, is designed to parse JSON-formatted data. The parse() method plays an important role in reading JSON data from various sources, including strings, files, or network responses.
🌐
Baeldung
baeldung.com › home › json › jackson › json in java
JSON in Java | Baeldung
May 11, 2024 - Next, let’s have a look at the most popular of these – Jackson. Jackson is a multi-purpose Java library for processing JSON data.
🌐
GeeksforGeeks
geeksforgeeks.org › java › parse-json-java
How to parse JSON in Java - GeeksforGeeks
December 23, 2025 - import java.io.FileReader; import java.util.Iterator; import java.util.Map; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; public class JSONReadExample { public static void main(String[] args) throws Exception { Object obj = new JSONParser().parse(new FileReader("JSONExample.json")); JSONObject jo = (JSONObject) obj; String firstName = (String) jo.get("firstName"); String lastName = (String) jo.get("lastName"); long age = (long) jo.get("age"); System.out.println(firstName); System.out.println(lastName); System.out.println(age); Ma
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › jackson-json-java-parser-api-example-tutorial
Jackson JSON Java Parser API Example Tutorial | DigitalOcean
August 3, 2022 - Jackson JSON Parser API provides easy way to convert JSON to POJO Object and supports easy conversion to Map from JSON data. Jackson supports generics too and directly converts them from JSON to object. For our example for JSON to POJO/Java object conversion, we will take a complex example ...
🌐
Jsoniter
jsoniter.com
Fastest JSON parser ever
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go.
🌐
GitHub
github.com › stleary › JSON-java
GitHub - stleary/JSON-java: A reference implementation of a JSON package in Java. · GitHub
The JSON-Java package is a reference implementation that demonstrates how to parse JSON documents into Java objects and how to generate new JSON documents from the Java classes.
Starred by 4.7K users
Forked by 2.6K users
Languages   Java
🌐
Coderanch
coderanch.com › t › 671052 › java › Parse-JSON-Java-knowing-incoming
Parse JSON in Java without knowing the incoming JSON format (Java in General forum at Coderanch)
Just like Jackson, Gson has an API to parse JSON into generic JsonObject, JsonArray etc. Look at the API documentation. A simple example: ... A great deal depends what you are going to do with that data after parsing. Do you need to reference it and use it throughout the remainder of the application? Or are you you just going to dump it somewhere and the specifics aren't important? I suspect the former, so I don't understand why it's such a "burden" to create classes that represent the data. That's what Java classes are for.
🌐
INNOQ
innoq.com › en › articles › 2022 › 02 › java-json
Processing JSON in Java
February 22, 2022 - In order to work in code with a JSONObject or JSONArray, a range of methods are available to us. For example, we can use has or isNull to check whether a field exists and is not null. Although isNull also returns true for fields that do not exist. In order to query individual field values, we can choose from an array of getXxx methods that return the value in the required Java data type.
🌐
Jakarta EE
jakarta.ee › learn › docs › jakartaee-tutorial › current › web › jsonp › jsonp.html
JSON Processing :: Jakarta EE Tutorial :: Jakarta EE Documentation
The code used in StreamingBean.java to write JSON data to a file is similar to the example in Writing JSON Data Using a Generator. The code to parse JSON data from a file is similar to the example in Reading JSON Data Using a Parser.
🌐
DZone
dzone.com › coding › java › how to read and parse a json file in java
How to Read and Parse a JSON File in Java
March 6, 2025 - Learn how to read and parse JSON files in Java with this step-by-step guide.
🌐
Reddit
reddit.com › r/javaexamples › 3 ways to parse json in java?
r/javaexamples on Reddit: 3 ways to parse JSON in Java?
August 27, 2024 - Well, there are many options in Java, from simply getting key value to converting it into an object, I have shared 3 of most common of them using Jackson, Gson and Json simple
🌐
LambdaTest Community
community.lambdatest.com › general discussions
How can I parse JSON in Java? - LambdaTest Community
April 2, 2024 - How can I parse JSON in Java? I have the following JSON text. How can I parse it to get the values of pageName, pagePic, post_id, etc.? { "pageInfo": { "pageName": "abc", "pagePic": "http://example.com/content.jpg" }, "posts": [ { "post_id": "123456789012_123456789012", "actor_id": "1234567890", ...
🌐
JSON Formatter
jsonformatter.org › json-parser
JSON Parser Online to parse JSON
Online JSON Parser helps to parse, view, analyze JSON data in Tree View.
🌐
JanBask Training
janbasktraining.com › community › java › how-to-parse-json-in-java
How to parse JSON in Java | JanBask Training Community
April 18, 2025 - Parsing JSON in Java can seem tricky at first, but with the right tools like Jackson or Gson, it becomes simple and efficient. This guide explains how to read, convert, a
🌐
Quora
quora.com › How-is-JSON-parse-used-in-Java
How is JSON.parse used in Java? - Quora
Answer (1 of 4): Use the below code snippet for Parsing JSON in JAVA [code]JSONObject obj = new JSONObject("{interests : [{interestKey:Dogs}, {interestKey:Cats}]}"); List list = new ArrayList (); JSONArray array = obj.getJSONArray("interests"); for(int i = 0 ; i