Showing results for json parser java
Search instead for jsonparser java

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
🌐
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
🌐
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
🌐
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.
🌐
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
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
Jsoniter
jsoniter.com
Fastest JSON parser ever
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go.
🌐
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.
🌐
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.
🌐
Latenode
community.latenode.com › other questions › rapidapi
Parsing non-standard JSON format in Java - RapidAPI - Latenode Official Community
May 10, 2025 - Hey everyone, I’m having trouble with a JSON response I got from an API. The problem is that some of the keys in the JSON aren’t wrapped in quotes. I think this might be called ‘Relaxed JSON’ or something similar. Here’s a snippet of what I’m dealing with: { name: "John Doe", age: ...
🌐
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]
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();
🌐
Jakarta EE
jakarta.ee › learn › docs › jakartaee-tutorial › current › web › jsonp › jsonp.html
JSON Processing :: Jakarta EE Tutorial :: Jakarta EE Documentation
The filewritten.xhtml page contains a text area that displays JSON data. The parsed.xhtml page contains a table that lists the events from the parser. The StreamingBean.java managed bean, a session-scoped managed bean that stores the data from the form and directs the navigation between the ...
🌐
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.