for your example:

{'profiles': [{'name':'john', 'age': 44}, {'name':'Alex','age':11}]}

you will have to do something of this effect:

JSONObject myjson = new JSONObject(the_json);
JSONArray the_json_array = myjson.getJSONArray("profiles");

this returns the array object.

Then iterating will be as follows:

    int size = the_json_array.length();
    ArrayList<JSONObject> arrays = new ArrayList<JSONObject>();
    for (int i = 0; i < size; i++) {
        JSONObject another_json_object = the_json_array.getJSONObject(i);
            //Blah blah blah...
            arrays.add(another_json_object);
    }

//Finally
JSONObject[] jsons = new JSONObject[arrays.size()];
arrays.toArray(jsons);

//The end...

You will have to determine if the data is an array (simply checking that charAt(0) starts with [ character).

Hope this helps.

Answer from Buhake Sindi on Stack Overflow
Top answer
1 of 3
58

for your example:

{'profiles': [{'name':'john', 'age': 44}, {'name':'Alex','age':11}]}

you will have to do something of this effect:

JSONObject myjson = new JSONObject(the_json);
JSONArray the_json_array = myjson.getJSONArray("profiles");

this returns the array object.

Then iterating will be as follows:

    int size = the_json_array.length();
    ArrayList<JSONObject> arrays = new ArrayList<JSONObject>();
    for (int i = 0; i < size; i++) {
        JSONObject another_json_object = the_json_array.getJSONObject(i);
            //Blah blah blah...
            arrays.add(another_json_object);
    }

//Finally
JSONObject[] jsons = new JSONObject[arrays.size()];
arrays.toArray(jsons);

//The end...

You will have to determine if the data is an array (simply checking that charAt(0) starts with [ character).

Hope this helps.

2 of 3
1

You can prefer quick-json parser to meet your requirement...

quick-json parser is very straight forward, flexible, very fast and customizable. Try this out

[quick-json parser] (https://code.google.com/p/quick-json/) - quick-json features -

  • Compliant with JSON specification (RFC4627)

  • High-Performance JSON parser

  • Supports Flexible/Configurable parsing approach

  • Configurable validation of key/value pairs of any JSON Heirarchy

  • Easy to use # Very Less foot print

  • Raises developer friendly and easy to trace exceptions

  • Pluggable Custom Validation support - Keys/Values can be validated by configuring custom validators as and when encountered

  • Validating and Non-Validating parser support

  • Support for two types of configuration (JSON/XML) for using quick-json validating parser

  • Require JDK 1.5 # No dependency on external libraries

  • Support for Json Generation through object serialization

  • Support for collection type selection during parsing process

For e.g.

JsonParserFactory factory=JsonParserFactory.getInstance();
JSONParser parser=factory.newJsonParser();
Map jsonMap=parser.parseJson(jsonString);
๐ŸŒ
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 - Using Jackson's ObjectMapper class, it's easy to read values and map them to an object, or an array of objects. We just use the readValue() method, passing the JSON contents and the class we'd like to map to.
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ gson โ€บ gson โ€“ parse json array to java array or list
Gson - Parse JSON Array to Java Array or List
April 4, 2023 - We can use the fromJson() method in the usual manner and it will parse the JSON array correctly to the required java array or list.
๐ŸŒ
Java Code Geeks
javacodegeeks.com โ€บ home โ€บ core java
Converting a JSON Object to a JSON Array in Java - Java Code Geeks
August 1, 2025 - To convert this object into a JSON array, the code first transforms the JSONObject into a Map using toMap(), then extracts only the values from that map using values(), and wraps those values in a new JSONArray.
๐ŸŒ
Kode Java
kodejava.org โ€บ how-do-i-convert-array-into-json
How do I convert array into JSON? - Learn Java by Examples
May 31, 2024 - To convert JSON to Array using Jackson library you can do the following: String jsonArray = "[{\"title\":\"Java in Action\"}, {\"title\":\"Spring in Action\"}]"; ObjectMapper objectMapper = new ObjectMapper(); try { Book[] books = objectMapper.readValue(jsonArray, Book[].class); for (Book book : books) { System.out.println(book); } } catch (IOException e) { e.printStackTrace(); } Reply ยท
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java array โ€บ convert json object to json array in java
Convert JSON Object to JSON Array in Java | Baeldung
August 24, 2025 - Jackson is a multi-purpose Java library for processing JSON data. It provides greater control over JSON structures using its capabilities. Although Jackson primarily works with its tree model, we can still integrate it with JSONObject by converting it internally. Letโ€™s write a method that accepts a JSONObject, transforms it into Jacksonโ€™s internal model, and returns an ArrayNode:
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-convert-json-array-to-arraylist-in-java
How to Convert JSON Array to ArrayList in Java - Javatpoint
How to Convert JSON Array to ArrayList in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2013 โ€บ 04 โ€บ convert-json-array-to-string-array-list-java-from.html
How to Convert JSON array to String array in Java - GSon example
Java programming tutorial to convert JSON array to String array with example, by using Gson library. Though you can also use other open source library, Gson seems easy to me.
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-convert-a-json-array-to-array-using-json-lib-api-in-java
How to convert a JSON array to array using JSON-lib API in Java?\\n
We can convert a JSON array to array by using the toArray() method of JSONArray class. This method produces an Object[] with the contents of JSONArray. ... import java.util.Arrays; import net.sf.json.JSONArray; public class ConvertJSONArrayToArrayTest { public static void main(String[] args) ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-convert-json-array-to-string-array-in-java
How to Convert JSON Array to String Array in Java? - GeeksforGeeks
July 23, 2025 - JavaScript. They can be understood as a collection of data (strings, numbers, booleans) in an indexed manner. Given a JSON array, we will discuss how to convert it into a String array in Java.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ how to parse json array with jackson
How to parse JSON Array with Jackson | mkyong.com
April 23, 2024 - In Jackson, we can convert the JSON array to an Array or List. ... package com.mkyong.json.jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.mkyong.json.model.Person; import java.util.List; public class JsonArrayToObjectExample { public static void main(String[] args) throws JsonProcessingException { String jsonArray = "[{\"name\":\"mkyong\", \"age\":42}, {\"name\":\"ah pig\", \"age\":20}]"; ObjectMapper mapper = new ObjectMapper(); // 1.
๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ converting-a-json-simple-array-to-arrayin-java
Converting a JSON Simple Array to an Array in Java โ€” javathinking.com
Use Strongly-Typed Arrays: Always try to use strongly-typed Java arrays to avoid type-related issues. Handle Null Values: Check for null values in the JSON array before converting it to a Java array and handle them appropriately.
Top answer
1 of 2
4

Found it :)

try {
            response = new JSONObject(con.query("history", parameters));
            JSONArray data = response.getJSONArray("data");
            for(int i = 0; i < data.length(); i++) {
                try {
                    episodeList.add(new Episode((JSONObject) data.get(i)));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
2 of 2
1
//         is = entity.getContent();
ArrayList<String> myList = new ArrayList<String>();


              //convert response to string
            try{

                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                result = sb.toString();


            } catch (Exception e) {
                Log.e("log_tag", "Error converting result "+e.toString());
            }




            //parse json data
            try{
                    jArray = new JSONArray(result);


                    for(int i=0;i<jArray.length();i++){

                        json_data = jArray.getJSONObject(i);

                        myList.add(json_data.getString("id"));
                        Log.i("log_tag","id: " + json_data.getString("id"));
                    }

            }
            catch(JSONException e){
                    Log.e("log_tag", "Error parsing data "+e.toString());
            }


return myList;

// then u can recieve this myList :

ArrayList<String> get_data_id = postData();
// get_data_id = myList
get_data_id.get(0) - it is first element,
get_data_id.get(1) - it is second element

.... EXAMPLE

json data is : [{"id":"1"},{"id":"2"},{"id":"3"},{"id":"4"},{"id":"5"},{"id":"6"}]
                        {in loop}   myList.add(json_data.getString("id"));
get_data_id.get(0) = 1
get_data_id.get(1) = 2
get_data_id.get(2) = 3
..........
:)

Good Luck

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-convert-json-array-object-to-java-object
How to Convert JSON Array Object to Java Object? - GeeksforGeeks
July 23, 2025 - In the above code, we have a JSON string jsonString representing an array of user objects. We have created an ObjectMapper instance from the Jackson library, which helps with JSON processing. We have used the readValue() method of the ObjectMapper to convert the JSON string into an array of User objects.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 697439 โ€บ java โ€บ convert-JSON-Array-arraylist
how to convert JSON Array to arraylist (Java in General forum at Coderanch)
I've read about GSON and a few article to do this but i still don't understand. Can you give me example how to do this? thanks. Hi Melody, You can use jackson library to convert json object to arraylist, first, you need to create a POJO second , create a method that convert to ArrayList Object, ...