No need to go with GSON for this; Jackson can do either plain Maps/Lists:

ObjectMapper mapper = new ObjectMapper();
Map<String,Object> map = mapper.readValue(json, Map.class);

or more convenient JSON Tree:

JsonNode rootNode = mapper.readTree(json);

By the way, there is no reason why you could not actually create Java classes and do it (IMO) more conveniently:

public class Library {
  @JsonProperty("libraryname")
  public String name;

  @JsonProperty("mymusic")
  public List<Song> songs;
}
public class Song {
  @JsonProperty("Artist Name") public String artistName;
  @JsonProperty("Song Name") public String songName;
}

Library lib = mapper.readValue(jsonString, Library.class);
Answer from StaxMan on Stack Overflow
🌐
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 ...
Discussions

Parsing JSON Object in Java - Stack Overflow
In Java I want to parse the above json object and store the values in an arraylist. More on stackoverflow.com
🌐 stackoverflow.com
How to parse JSON in Java - Stack Overflow
Re-protected it now to prevent low rep answers and such like, while waiting for a mod. ... This question is being discussed on Meta. ... @ImanAkbari What JSON library is built-in? I found Java Specification Request 353 but that just specifies what objects should exist, it is not an implementation. More on stackoverflow.com
🌐 stackoverflow.com
java - Parse json to object - Stack Overflow
As per your question its seems ... the json data of type object. To parse the data we can use the above two parsers mentioned by d__k. I have been using Jackson and we have a ObjectMapper class which converts the data in the specified type. We can use ObjectMapper#readValue to read the data into java ... More on stackoverflow.com
🌐 stackoverflow.com
Converting Json to Java object
Jackson is a library that people use to deserialize json to Java. More on reddit.com
🌐 r/javahelp
10
7
December 13, 2022
🌐
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 - The Gson is my second favorite JSON parsing library. It probably provides the cleaner code to parse JSON in Java. With no checked exception to handle, you literally need to follow two lines of code to parse your JSON into a Java object.
🌐
Oracle
oracle.com › java › technical details
Java API for JSON Processing
Listing 1. Example of JSON ... format with their RESTful web services. The Java API for JSON Processing (JSR 353) provides portable APIs to parse, generate, transform, and query JSON using object model and streaming APIs....
🌐
DevQA
devqa.io › how-to-parse-json-in-java
How to Parse JSON in Java
November 8, 2019 - First, we need to convert the JSON string into a JSON Object, using JSONObject class.
Top answer
1 of 5
158

I'm assuming you want to store the interestKeys in a list.

Using the org.json library:

JSONObject obj = new JSONObject("{interests : [{interestKey:Dogs}, {interestKey:Cats}]}");

List<String> list = new ArrayList<String>();
JSONArray array = obj.getJSONArray("interests");
for(int i = 0 ; i < array.length() ; i++){
    list.add(array.getJSONObject(i).getString("interestKey"));
}
2 of 5
13
public class JsonParsing {

public static Properties properties = null;

public static JSONObject jsonObject = null;

static {
    properties = new Properties();
}

public static void main(String[] args) {

    try {

        JSONParser jsonParser = new JSONParser();

        File file = new File("src/main/java/read.json");

        Object object = jsonParser.parse(new FileReader(file));

        jsonObject = (JSONObject) object;

        parseJson(jsonObject);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

public static void getArray(Object object2) throws ParseException {

    JSONArray jsonArr = (JSONArray) object2;

    for (int k = 0; k < jsonArr.size(); k++) {

        if (jsonArr.get(k) instanceof JSONObject) {
            parseJson((JSONObject) jsonArr.get(k));
        } else {
            System.out.println(jsonArr.get(k));
        }

    }
}

public static void parseJson(JSONObject jsonObject) throws ParseException {

    Set<Object> set = jsonObject.keySet();
    Iterator<Object> iterator = set.iterator();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (jsonObject.get(obj) instanceof JSONArray) {
            System.out.println(obj.toString());
            getArray(jsonObject.get(obj));
        } else {
            if (jsonObject.get(obj) instanceof JSONObject) {
                parseJson((JSONObject) jsonObject.get(obj));
            } else {
                System.out.println(obj.toString() + "\t"
                        + jsonObject.get(obj));
            }
        }
    }
}}
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
Find elsewhere
🌐
Stack Abuse
stackabuse.com › how-to-convert-json-object-to-java-object-with-jackson
How to Convert JSON Object to Java Object with Jackson
February 27, 2023 - To convert a JSON object into a Java object, you'll use the readValue() method of the ObjectMapper instance, which deserializes it into the provided class reference:
🌐
GeeksforGeeks
geeksforgeeks.org › java › parse-json-java
How to parse JSON in Java - GeeksforGeeks
December 23, 2025 - Note : JSON objects are unordered by definition, so key order is not guaranteed. This example reads and parses the previously created JSON file. ... 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 = (
🌐
Medium
medium.com › @AlexanderObregon › javas-jsonparser-parse-method-explained-76b126f6110e
Java’s JsonParser.parse() Method Explained | Medium
October 13, 2024 - It reads the JSON file and automatically converts it into a Java object, making it easier to work with structured data. Gson: Gson, developed by Google, is another popular library for working with JSON in Java. Like Jackson, it allows for object mapping, meaning JSON data can be converted into Java objects with minimal code. One of Gson’s strengths is its simplicity and small footprint, making it a lightweight option for developers who need JSON parsing but don’t want the full overhead of a large library.
🌐
Reflectoring
reflectoring.io › jackson
All You Need To Know About JSON Parsing With Jackson
July 15, 2022 - ObjectMapper is the most commonly ... It lives in com.fasterxml.jackson.databind. The readValue() method is used to parse (deserialize) JSON from a String, Stream, or File into POJOs....
🌐
Mkyong
mkyong.com › home › java › how to parse json string with jackson
How to parse JSON string with Jackson - Mkyong.com
April 23, 2024 - { "name" : "mkyong", "age" : 42, "position" : [ "Founder", "CTO", "Writer", "Minimalists" ], "skills" : [ "java", "python", "node", "kotlin" ], "salary" : { "2018" : 14000, "2012" : 12000, "2010" : 10000 }, "active" : false } ... package com.mkyong.json.jackson; import com.fasterxml.jackson.databind.ObjectMapper; import com.mkyong.json.model.Staff; import java.io.File; import java.io.IOException; public class ConvertJsonToJavaObjectExample { private static final ObjectMapper MAPPER = new ObjectMapper(); public static void main(String[] args) throws IOException { // Convert JSON file to Java ob
🌐
Java67
java67.com › 2015 › 02 › how-to-parse-json-tofrom-java-object.html
How to Parse JSON in Java Object using Jackson - Example Tutorial | Java67
Hello guys, if you are wondering how to parse JSON in Java then don't worry, there are many options. In the last article, I have shown you 3 ways to parse JSON in Java in this example, You will learn how to parse a JSON String to Java and how to convert Java Object to JSON format using Jackson.
🌐
Java67
java67.com › 2016 › 10 › 3-ways-to-convert-string-to-json-object-in-java.html
3 ways to convert String to JSON object in Java? Examples | Java67
Also, Jackson doesn't support J2ME, but one of the main advantages of using Jackson is that it supports streaming which can be used to parse huge JSON responses without loading it fully in memory. Jackson is a very popular and efficient Java library to map Java objects to JSON and vice-versa.
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java | Baeldung
June 20, 2025 - A JSONArray is an ordered collection of values, resembling Java’s native Vector implementation: Values can be anything from a Number, String, Boolean, JSONArray, or JSONObject to even a JSONObject.NULL object · It’s represented by a String wrapped within square brackets and consists of a collection of values separated by commas · Like JSONObject, it has a constructor that accepts a source String and parses it to construct a JSONArray
🌐
Baeldung
baeldung.com › home › json › jackson › intro to the jackson objectmapper
Intro to the Jackson ObjectMapper | Baeldung
December 9, 2025 - The simple readValue API of the ObjectMapper is a good entry point. We can use it to parse or deserialize JSON content into a Java object.
🌐
javaspring
javaspring.net › blog › parse-json-to-java-object
Parsing JSON to Java Objects: A Comprehensive Guide — javaspring.net
Parsing JSON to Java objects is a common task in Java development. In this blog post, we have covered the fundamental concepts, popular JSON parsing libraries (Gson and Jackson), usage methods, common practices, and best practices.
🌐
iO Flood
ioflood.com › blog › json-to-java-object
Converting JSON data to Java objects: A How-to Guide
February 26, 2024 - If you’re interested in diving deeper into JSON to Java object conversion, here are some resources you might find helpful: Fundamentals Covered: Java Casting – Understand how to use casting to access superclass and subclass members in Java. Java ParseInt Method – Master parsing integer values from strings for accurate data conversion in Java.