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

Parse json file in Java?
I'm curious what you googled that didn't return any results. You should use keywords to narrow it down to the official JavaDocs. JsonParser . At least this is a good place to start. More on reddit.com
🌐 r/learnprogramming
5
2
November 28, 2022
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
January 3, 2013
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
February 2, 2022
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
April 27, 2015
🌐
DigitalOcean
digitalocean.com › community › tutorials › jackson-json-java-parser-api-example-tutorial
Jackson JSON Java: Parser API Examples & Tutorial | DigitalOcean
August 3, 2022 - Parse JSON in Java using Jackson library. Complete tutorial with examples for serialization, deserialization, annotations, and advanced JSON processing.
🌐
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
🌐
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.
🌐
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
Find elsewhere
🌐
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
🌐
Jsoniter
jsoniter.com
Fastest JSON parser ever
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go.
🌐
Oracle
oracle.com › java › technical details
Java API for JSON Processing
The Java API for JSON Processing provides portable APIs to parse, generate, transform, and query JSON.
🌐
Eclipse Che
eclipsesource.com › blogs › 2013 › 04 › 18 › minimal-json-parser-for-java
A Fast and Minimal JSON Parser for Java
April 18, 2013 - If you’re looking for a bare-bones JSON parser with zero dependencies, you are welcome to use minimal-json. It goes without saying that it’s developed test-driven and complies with the RFC. The code lives at github and is EPL-licensed. It is also included in RAP. I didn’t setup a build. If you would like to use the code, I suggest that you simply copy these 10 Java files to your project.
🌐
GitHub
github.com › mitchhentges › json-parse
GitHub - mitchhentges/json-parse: Super-fast Java JSON parser
A tool to quickly parse JSON into Java maps and lists.
Starred by 17 users
Forked by 6 users
Languages   Java 100.0% | Java 100.0%
🌐
JAXB
javaee.github.io › javaee-spec › javadocs › javax › json › stream › JsonParser.html
JsonParser (Java(TM) EE 8 Specification APIs)
JsonParser parses JSON using the pull parsing programming model. In this model the client code controls the thread and calls the method next() to advance the parser to the next state after processing each element.
🌐
Blogger
javarevisited.blogspot.com › 2022 › 03 › 3-examples-to-parse-json-in-java-using.html
3 ways to parse JSON String to Object in Java [Jackson, Gson, and json-simple Example]
April 22, 2023 - We have a class called JSONParser which is similar to ObjectMapper of Jackson but here we are parsing into JSONObject rather than a POJO, hence we need to extract each attribute one by one to create a Java object. JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse(JSON); String title = (String) json.getOrDefault("title", ""); String author = (String) json.getOrDefault("author", ""); int price = ((Long) json.getOrDefault("price", 0)).intValue(); int year = ((Long) json.getOrDefault("year", 2018)).intValue(); int edition = ((Long) json.getOrDefault("edition", 2)).intValue(); int ratings = ((Long) json.getOrDefault("ratings", 0)).intValue();
🌐
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.
🌐
Temboo
temboo.com › java › parsing-json
Parsing JSON in Java
3 You get a whole bunch of JSON in the Response output. These are the results of the search. Next we'll see how to parse through this response in Java and pick out only the pieces we're interested in.
🌐
Sentry
sentry.io › sentry answers › java › how do i parse json in java?
How Do I Parse JSON in Java? | Sentry
October 15, 2024 - You can easily use the org.json library to parse JSON in Java.
🌐
GitHub
github.com › ralfstx › minimal-json
GitHub - ralfstx/minimal-json: A fast and small JSON parser and writer for Java · GitHub
A fast and minimal JSON parser and writer for Java.
Starred by 738 users
Forked by 188 users
Languages   Java 93.9% | JavaScript 4.4%
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java | Baeldung
June 20, 2025 - We use classes from the JSON-Java library to parse and manipulate JSON in Java. We also know this library as org.json.