You are asking Jackson to parse a StudentList. Tell it to parse a List (of students) instead. Since List is generic you will typically use a TypeReference

List<Student> participantJsonList = mapper.readValue(jsonString, new TypeReference<List<Student>>(){});
Answer from Manos Nikolaidis on Stack Overflow
🌐
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
Discussions

java - Parsing JSON list of objects - Stack Overflow
How would I parse this to pojo? {"name":"test","value":"8893"}, {"name":"test2","value":"1"}, {"name":"test3","value":"68"}, {"name":"test4","value":"26824212473"} ... List payload = mapper.readValue(obj.getjSONRequest(), new TypeReference>() { }); I get; Cannot deserialize instance ofjava.util.ArrayListout of START_OBJECT ... More on stackoverflow.com
🌐 stackoverflow.com
February 19, 2018
java - How to parse list of object from Json Object - Stack Overflow
I need help to parse this JSON, i have some problems. The object name is "random" I need to create Java object with list of generic objects and parse Json How i can parse every object with random ... More on stackoverflow.com
🌐 stackoverflow.com
October 17, 2017
Parse JSON Response - List of Objects - Salesforce Stack Exchange
Disclaimer: I am new to JSON parsing in Salesforce, trying to up skill. I am trying to extract the picture links, lets say the 'large' to be able to add to a contact record on record creation; { ... More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
July 6, 2021
Parsing JSON array into java.util.List with Gson - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... And now I want to parse that JsonArray into a java.util.List... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Baeldung
baeldung.com › home › json › jackson › convert json array to java list
Convert JSON Array to Java List | Baeldung
August 13, 2025 - Then, we use the readValue() method of the ObjectMapper object to convert the JSON array String to a List. Similar to the assertion discussed previously, finally, we compare a specific field from the String JSON array to the jacksonList ...
🌐
Stack Exchange
salesforce.stackexchange.com › questions › 348749 › parse-json-response-list-of-objects
Parse JSON Response - List of Objects - Salesforce Stack Exchange
July 6, 2021 - Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('callout:RandomUserGenerator/?gender=female&inc=picture&noinfo'); request.setMethod('GET'); HttpResponse response = http.send(request); // Sucessful, then parse response if (response.getStatusCode() == 200) { Map<String, Object> jsonResp = (Map<String, Object>) JSON.deserializeUntyped(response.getBody()); List<Object> results = (List<Object>) jsonResp.get('results'); for(Object res : results){ Map<String, Object> resultMap = (Map<String, Object>) res; Map<String, Object> resultObj = (Map<String, Object>) resultMap.get('result'); System.debug(resultObj.get('large')); } }
Find elsewhere
Top answer
1 of 6
321

Definitely the easiest way to do that is using Gson's default parsing function fromJson().

There is an implementation of this function suitable for when you need to deserialize into any ParameterizedType (e.g., any List), which is fromJson(JsonElement json, Type typeOfT).

In your case, you just need to get the Type of a List<String> and then parse the JSON array into that Type, like this:

import java.lang.reflect.Type;
import com.google.gson.reflect.TypeToken;

JsonElement yourJson = mapping.get("servers");
Type listType = new TypeToken<List<String>>() {}.getType();

List<String> yourList = new Gson().fromJson(yourJson, listType);

In your case yourJson is a JsonElement, but it could also be a String, any Reader or a JsonReader.

You may want to take a look at Gson API documentation.

2 of 6
19

Below code is using com.google.gson.JsonArray. I have printed the number of element in list as well as the elements in List

import java.util.ArrayList;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;


public class Test {

    static String str = "{ "+ 
            "\"client\":\"127.0.0.1\"," + 
            "\"servers\":[" + 
            "    \"8.8.8.8\"," + 
            "    \"8.8.4.4\"," + 
            "    \"156.154.70.1\"," + 
            "    \"156.154.71.1\" " + 
            "    ]" + 
            "}";

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {

            JsonParser jsonParser = new JsonParser();
            JsonObject jo = (JsonObject)jsonParser.parse(str);
            JsonArray jsonArr = jo.getAsJsonArray("servers");
            //jsonArr.
            Gson googleJson = new Gson();
            ArrayList jsonObjList = googleJson.fromJson(jsonArr, ArrayList.class);
            System.out.println("List size is : "+jsonObjList.size());
                    System.out.println("List Elements are  : "+jsonObjList.toString());


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

OUTPUT

List size is : 4

List Elements are  : [8.8.8.8, 8.8.4.4, 156.154.70.1, 156.154.71.1]
🌐
Reddit
reddit.com › r/javahelp › how to parse json to get size of the list using jsonobject in java?
r/javahelp on Reddit: How to parse json to get size of the list using jsonObject in 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.

Top answer
1 of 2
2
That JSON is an object (it starts with {). You can't parse it as an array. You have to parse it as a JSON object and then read the value of the array property of the object that you are interested in.
2 of 2
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Coderanch
coderanch.com › t › 685163 › open-source › JSON-List-Lists-parse-properly
JSON List of Lists not parse properly [Solved] (Open Source Projects forum at Coderanch)
September 28, 2017 - Hi, Thanks for response Rob, it helps me alot. I am able to solve the issue. The things I have applied are: 1. Extends the interface Component with Serializable. 2. Use another json library for conver java to json. The library is Jackson JSON Java Parser. Hope it will help someone.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Converting JSON Array to Java List with Gson - Java Code Geeks
April 25, 2024 - We parse a JSON array into a JsonArray using Gson’s JsonParser. Then, we iterate over each element of the array, converting them into Java objects using Gson’s fromJson() method. Finally, we add each Java object to a List.
🌐
TutorialsPoint
tutorialspoint.com › how-to-read-parse-json-array-using-java
How to read/parse JSON array using Java?
May 5, 2025 - import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Iterator; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; public class ReadingArrayFromJSON { public static void main(String args[]) { //Creating a JSONParser object JSONParser jsonParser = new JSONParser(); try { //Parsing the contents of the JSON file JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader("E:/test.json")); //Forming URL System.out.println("Conten
🌐
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 - The following code parses a JSON array containing person data and converts it into a list of Java Person objects using the JSONArray and JSONObject classes.
🌐
Attacomsian
attacomsian.com › blog › jackson-convert-json-array-to-from-java-list
Convert JSON array to a list using Jackson in Java
November 6, 2022 - To convert the JSON array into an equivalent Java array, you should do the following: User[] users = new ObjectMapper().readValue(json, User[].class); If your JSON array is stored in a JSON file, you can still read and parse its content to a list of Java Objects, as shown below:
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-objectmapper.html
Jackson ObjectMapper
Notice the TypeReference parameter passed to readValue(). This parameter tells Jackson to read a List of Car objects. The Jackson ObjectMapper can also read a Java Map from a JSON string. This can be useful if you do not know ahead of time the exact JSON structure that you will be parsing.
🌐
GitHub
gist.github.com › cblunt › 7865d8afc566287a9d4a
Parsing list of objects in JSON · GitHub
Parsing list of objects in JSON · Raw · ProductsActivity.java · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
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....
🌐
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.