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
🌐
Baeldung
baeldung.com › home › java › java list › converting a java list to a json array
Converting a Java List to a Json Array | Baeldung
June 18, 2025 - Furthermore, web services and APIs often rely on JSON format to provide public data in a standardized manner. Its versatility makes it compatible with modern programming languages, allowing seamless integration across different platforms and technologies. In this scenario, let’s consider a Java list named “articles” that contains elements as follows: public List<String> list = Arrays.asList("Article 1", "Article 2", "Article 3"); public String expectedJsonArray = "[\"Article 1\",\"Article 2\",\"Article 3\"]";
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);
Discussions

Convert normal Java Array or ArrayList to Json Array in android - Stack Overflow
Is there any way to convert a normal Java array or ArrayList to a Json Array in Android to pass the JSON object to a webservice? More on stackoverflow.com
🌐 stackoverflow.com
java - Convert json String to array of Objects - Stack Overflow
Sign up to request clarification or add additional context in comments. ... +1. Also, if a collection is preferred like List, you can wrap the fromJson call in Arrays.asList 2013-08-27T06:49:29.03Z+00:00 ... It is working but for the same thing i have one field for date with value Tue Aug 27 06:07:32 UTC 2013. It says error on java... More on stackoverflow.com
🌐 stackoverflow.com
How to turn json objects into an array of json objects using Java?
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. More on reddit.com
🌐 r/javahelp
7
4
June 28, 2022
android - Convert Json Array to normal Java list - Stack Overflow
Is there a way to convert JSON Array to normal Java Array for android ListView data binding? More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
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 - Learn to use Google GSON library to deserialize or convert JSON, containing JSON array as root or member, to Java Array or List of objects.
🌐
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.
🌐
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 - In this article, we've used Jackson to parse and map the values from a JSON String and file into a Java array and 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.
Find elsewhere
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › Converting-JSON-to-Java-Object-Array › td-p › 153155
Solved: Converting JSON to Java Object Array - Cloudera Community - 153155
February 1, 2017 - Here is the correct example to parse your JSON. import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class JSONParser { public static void main(String[] args) throws IOException { try(Reader reader = new InputStreamReader(JsonToJava.class.getResourceAsStream("Server1.json"), "UTF-8")){ Gson gson = new GsonBuilder().create(); Person p = gson.fromJson(reader, Person.class); System.out.println(p); } } }
🌐
Reddit
reddit.com › r/javahelp › how to turn json objects into an array of json objects using java?
r/javahelp on Reddit: How to turn json objects into an array of json objects using Java?
June 28, 2022 -

Hi. I'm new to java and stuck wondering how I would go about turning something like this: {} {} {} into this: [{},{},{}]. I'm trying to figure out how to do this to my incoming json data using Java. The data has like 20 similar objects, with the same keys but with constantly changing values.

Any help is much appreciated.

Sincerely,

your friendly neighborhood noob

Top answer
1 of 2
4
Look into Collections. you can use a List with List.of(obj1, obj2,...), The return here is going to be immutable and serializable, alternatively Arrays.asList({obj1, obj2,...}). Again, check out java.util.collections for more details
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.
🌐
TutorialsPoint
tutorialspoint.com › how-to-write-create-a-json-array-using-java
How to Write/create a JSON array using Java?
September 6, 2023 - Create a JSON array by instantiating the JSONArray class and add, elements to the created array using the add() method of the JSONArray class.
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonArray.html
JsonArray (Java(TM) EE 7 Specification APIs)
ClassCastException - if the value at the specified position is not assignable to the JsonObject type ... Returns the array value at the specified position in this array.
🌐
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
This Java example uses the GSON library to create a List of String from JSON array and further Java standard library to convert List to an array. Instead of declaring JSON array in Code, which we did here for demonstration purposes, you can also read input from a file, database, or any URL.
🌐
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:
🌐
TutorialsPoint
tutorialspoint.com › how-to-read-parse-json-array-using-java
How to read/parse JSON array using Java?
May 5, 2025 - The iterator() method of the JSONArray class returns an Iterator object, using which you can iterate through the contents of the current array. Iterator<String> iterator = jsonArray.iterator(); while(iterator.hasNext()) { System.out.println(iterator.next()); } Below is an example of a Java program that parses the above-created sample.json file, reads its contents, and displays them.
🌐
Stleary
stleary.github.io › JSON-java › org › json › JSONArray.html
JSONArray
If the value is not a string and is not null, then it is converted to a string. ... A String value. public String optString(int index, String defaultValue) Get the optional string associated with an index. The defaultValue is returned if the key is not found. ... A String value. ... Append a boolean value. This increases the array's length by one. ... Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
🌐
BeginnersBook -
beginnersbook.com › home › java › convert json array to arraylist in java
Convert JSON Array to ArrayList in Java
June 13, 2024 - 2. Parse the JSON Array and Convert to ArrayList: Let’s write the code to convert the JSON array to ArrayList. import org.json.JSONArray; import org.json.JSONObject; import java.util.ArrayList; public class JsonToArrayList { public static void main(String[] args) { // This is our JSON array contains name and age String jsonArrayString = "[{\"name\":\"Chaitanya\", \"age\":37}, {\"name\":\"Rahul\", \"age\":34}]"; // Convert JSON array to JSONArray JSONArray jsonArray = new JSONArray(jsonArrayString); // Convert JSONArray to ArrayList ArrayList<JSONObject> arrayList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { arrayList.add(jsonArray.getJSONObject(i)); } // Print the ArrayList for (JSONObject obj : arrayList) { System.out.println(obj.toString()); } } }