Instead of using JSONObject you may use JSONArray. If you really need to convert it to a List you may do something like:

List<JSONObject> list = new ArrayList<JSONObject>();
try {
    int i;
    JSONArray array = new JSONArray(string);
    for (i = 0; i < array.length(); i++)
        list.add(array.getJSONObject(i);
} catch (JSONException e) {
    System.out.println(e.getMessage());
}
Answer from Victor Dodon on Stack Overflow
🌐
Baeldung
baeldung.com › home › json › jackson › convert json array to java list
Convert JSON Array to Java List | Baeldung
August 13, 2025 - We can specify the type of the target List using the TypeToken class. In the above example, we’ve defined the target type as List<Product>. Then, we use the fromJson() method of the Gson object to convert the JSON array String to a List.
Discussions

java - converting JSONObject to Object list - Stack Overflow
You've shown incomplete JSON. products is a JSON array that will map to a List. But the JSON containing products will not. ... Considering that your request or string data is in JSONObject jsonArray. More on stackoverflow.com
🌐 stackoverflow.com
May 22, 2017
Casting list of JSONObject to JSONObject throws ClassCastException
When calling the toList() method of a JSONArray which contains JSONObject the returned list contains HashMap elements. More on github.com
🌐 github.com
4
October 22, 2019
Convert Single Json Object to a List
Hello bubblers. I am working with crm api that allows me to call an option set field directly. The response is a single json object called data, with a nested list of key value pairs. It is those key value pairs I would like to use as a dynamic drop down. Unfortunately, bubble only recognizes ... More on forum.bubble.io
🌐 forum.bubble.io
0
1
October 4, 2021
java - JSON: Get list of JSON Objects - Stack Overflow
Sign up to request clarification or add additional context in comments. ... This is incorrect. You can not convert JSONObject to JSONArray. First line needs to be corrected. More on stackoverflow.com
🌐 stackoverflow.com
🌐
How to do in Java
howtodoinjava.com › home › convert json array to list: gson, jackson and org.json
Convert JSON Array to List: Gson, Jackson and Org.json
September 25, 2023 - List<Person> readPersonListFromJsonArray(String json) { JSONArray jsonArray = new JSONArray(json); List<Person> personList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonPerson = jsonArray.getJSONObject(i); long id = jsonPerson.getLong("id"); String name = jsonPerson.getString("name"); int age = jsonPerson.getInt("age"); Person person = new Person(id, name, age); personList.add(person); } return personList; } In this article, we explored how to use Gson, Jackson, and Org.json libraries for converting a JSON array into a Java list.
🌐
Mkyong
mkyong.com › home › java › how to parse json array with jackson
How to parse JSON Array with Jackson - Mkyong.com
April 23, 2024 - package com.mkyong.json.jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.mkyong.json.model.Person; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; public class JsonArrayToObjectExample3 { public static void main(String[] args) throws JsonProcessingException { // Create a list of Person objects List<Person> people = Arrays.asList( new Person("mkyong", 42), new Person("ah pig", 20) ); // Wrap the list in a Map with "Person" as the key Map<String, List<Person>> wrapper
🌐
Stack Overflow
stackoverflow.com › questions › 31734264 › converting-jsonobject-to-object-list
java - converting JSONObject to Object list - Stack Overflow
May 22, 2017 - public class GsonTest { public static void main(String[] args) { Gson gson = new Gson(); Object obj; try { JsonParser parser = new JsonParser(); obj = parser.parse(new FileReader("C:\data.json")); JsonObject jsonObject = (JsonObject) obj; Data data = gson.fromJson(jsonObject, Data.class); } catch (JsonIOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonSyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
🌐
GitHub
github.com › stleary › JSON-java › issues › 491
Casting list of JSONObject to JSONObject throws ClassCastException · Issue #491 · stleary/JSON-java
October 22, 2019 - @Test public void shouldCastArrayOfJSONObjectsToList() { String a = "{\"a\": 1}"; String b = "{\"b\":2}"; String jsonString = "{\"list\":[" + a + "," + b + "]}"; JSONObject jsonObject = new JSONObject(jsonString); JSONArray jsonArray = jsonObject.getJSONArray("list"); List<JSONObject> jsonObjects = jsonArray.toList().stream().map(JSONObject.class::cast).collect(Collectors.toList()); assertEquals(jsonObjects.size(), 2); }
Author   ggavriilidis
Find elsewhere
🌐
Medium
medium.com › @papapapaya11 › exploring-various-ways-to-handle-jsonobject-in-java-6edef1f0561c
Exploring Various Ways to Handle JSONObject in Java | by Little Miss Brave | Medium
December 2, 2024 - String json = "{\"name\":\"Little Miss Brave\",\"age\":26}"; List<String> names = new ArrayList<>(); names.add("Little Miss Brave"); names.add("Amy"); names.add("Mandy"); JSONObject jsonObject = JSONObject.fromObject(json); JSONArray jsonArray = JSONArray.fromObject(names); System.out.println(jsonObject.toString()); // {"name":"Little Miss Brave","age":26} System.out.println(jsonArray.toString()); // ["Little Miss Brave","Amy","Mandy"]
🌐
Bubble
forum.bubble.io › need help › apis
Convert Single Json Object to a List - APIs - Bubble Forum
October 4, 2021 - Hello bubblers. I am working with crm api that allows me to call an option set field directly. The response is a single json object called data, with a nested list of key value pairs. It is those key value pairs I would like to use as a dynamic drop down. Unfortunately, bubble only recognizes ...
🌐
GitHub
gist.github.com › 4201429
Convert Android JSONObject/JSONArray to a standard Map/List. · GitHub
Convert Android JSONObject/JSONArray to a standard Map/List. - JsonHelper.java
🌐
Reddit
reddit.com › r/softwaretesting › how to parse json to get size of the list from jsonobject using java?
r/softwaretesting on Reddit: How to parse json to get size of the list from jsonObject using Java?
May 16, 2022 -

Hi, All,

I am facing problem while parsing json tried different ways to parse json ending up with error. I actually want to get the size of list present in jsonObject so that I can run a for loop till that size and get attributes accordingly.

Running to the error - org.json.JSONException : A JSONArray text must start with '[' at 1 [character 2 line 1]

Json is present on the below link :

https://reqres.in/api/users?page=2

Can you guys please help me with different code snippet how can it be achieved? Will be very thankful to you all.

🌐
Baeldung
baeldung.com › home › json › getting a value in jsonobject
Getting a Value in JSONObject | Baeldung
May 5, 2025 - First, when the value of a key is of JSONObject or JSONArray type, we need to propagate the recursive search down in that value. Second, when the key is found in the current recursive call, we need to add its mapped value to the returned result, regardless of whether the value is of a primitive type or not. ... public List<String> getValuesInObject(JSONObject jsonObject, String key) { List<String> accumulatedValues = new ArrayList<>(); for (String currentKey : jsonObject.keySet()) { Object value = jsonObject.get(currentKey); if (currentKey.equals(key)) { accumulatedValues.add(value.toString())
🌐
Stack Abuse
stackabuse.com › converting-json-array-to-a-java-array-or-list
Convert JSON Array to a Java Array or List with Jackson
September 8, 2020 - Thankfully, Jackson makes this task as easy as the last one, we just provide the File to the readValue() method: final ObjectMapper objectMapper = new ObjectMapper(); List<Language> langList = objectMapper.readValue( new File("langs.json"), new TypeReference<List<Language>>(){}); langList.forEach(x -> System.out.println(x.toString()));
🌐
Kotlin Discussions
discuss.kotlinlang.org › support
How to get listitems in JSONObject - Support - Kotlin Discussions
May 18, 2022 - Hello guys, my JSON is supposed to look like this. I am using import org.json.JSONObject {"zip":123, "people":[{"firstname":"Thomas", "lastname":"Tatum"}, {"firstname":"Drew", "lastname":"Uncle"}]} I have a MutableList, in the List are Person (it’s a data class with firstname and lastname).
🌐
Android Developers
developer.android.com › api reference › jsonobject
JSONObject | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
TutorialsPoint
tutorialspoint.com › how-can-we-add-a-jsonarray-to-jsonobject-in-java
How can we add a JSONArray to JSONObject in Java?
July 4, 2020 - It is a lightweight component and language independent. We can also add a JSONArray to JSONObject. We need to add a few items to an ArrayList first and pass this list to the put() method of JSONArray class and finally add this array to JSONObject using the put() method.
Top answer
1 of 5
20

Call getJSONObject() instead of getString(). That will give you a handle on the JSON object in the array and then you can get the property off of the object from there.

For example, to get the property "value" from a List<SomeClass> where SomeClass has a String getValue() and setValue(String value):

JSONObject obj = new JSONObject();
List<SomeClass> sList = new ArrayList<SomeClass>();

SomeClass obj1 = new SomeClass();
obj1.setValue("val1");
sList.add(obj1);

SomeClass obj2 = new SomeClass();
obj2.setValue("val2");
sList.add(obj2);

obj.put("list", sList);

JSONArray jArray = obj.getJSONArray("list");
for(int ii=0; ii < jArray.length(); ii++)
  System.out.println(jArray.getJSONObject(ii).getString("value"));
2 of 5
3

Let us assume that the class is Data with two objects name and dob which are both strings.

Initially, check if the list is empty. Then, add the objects from the list to a JSONArray

JSONArray allDataArray = new JSONArray();
List<Data> sList = new ArrayList<String>();

    //if List not empty
    if (!(sList.size() ==0)) {

        //Loop index size()
        for(int index = 0; index < sList.size(); index++) {
            JSONObject eachData = new JSONObject();
            try {
                eachData.put("name", sList.get(index).getName());
                eachData.put("dob", sList.get(index).getDob());
            } catch (JSONException e) {
                e.printStackTrace();
            }
            allDataArray.put(eachData);
        }
    } else {
        //Do something when sList is empty
    }
    

Finally, add the JSONArray to a JSONObject.

JSONObject root = new JSONObject();
    try {
        root.put("data", allDataArray);
    } catch (JSONException e) {
        e.printStackTrace();
    }

You can further get this data as a String too.

String jsonString = root.toString();