Here is some code using java 6 to get you started:

JSONObject jo = new JSONObject();
jo.put("firstName", "John");
jo.put("lastName", "Doe");

JSONArray ja = new JSONArray();
ja.put(jo);

JSONObject mainObj = new JSONObject();
mainObj.put("employees", ja);

Edit: Since there has been a lot of confusion about put vs add here I will attempt to explain the difference. In java 6 org.json.JSONArray contains the put method and in java 7 javax.json contains the add method.

An example of this using the builder pattern in java 7 looks something like this:

JsonObject jo = Json.createObjectBuilder()
  .add("employees", Json.createArrayBuilder()
    .add(Json.createObjectBuilder()
      .add("firstName", "John")
      .add("lastName", "Doe")))
  .build();
Answer from Grammin on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › how-to-write-create-a-json-array-using-java
How to Write/create a JSON array using Java?
Create a JSON array by instantiating the JSONArray class and add, elements to the created array using the add() method of the JSONArray class. JSONArray array = new JSONArray(); array.add("element_1"); array.add("element_2"); array.add("element_3"); After adding all the required elements add ...
People also ask

Can I create a JSONArray directly without JSONObjects?
Yes, you can create a JSONArray of primitive values like strings or numbers JSONArray array = new JSONArray(); array.put(“Value1”); array.put(“Value2”);
🌐
intellipaat.com
intellipaat.com › home › blog › how to create a correct jsonarray in java using jsonobject?
How to Create a Correct JSONArray in Java Using JSONObject?
How do I parse an existing JSON string into a JSONArray?
Use the JSONArray constructor: String jsonString = “[{“key”:”value”}]”; JSONArray jsonArray = new JSONArray(jsonString);
🌐
intellipaat.com
intellipaat.com › home › blog › how to create a correct jsonarray in java using jsonobject?
How to Create a Correct JSONArray in Java Using JSONObject?
How do I convert a JSONArray to a Java List?
You can iterate over the JSONArray and populate a Java List: List list = new ArrayList(); for (int i = 0; i < jsonArray.length(); i++) { list.add(jsonArray.getJSONObject(i)); }
🌐
intellipaat.com
intellipaat.com › home › blog › how to create a correct jsonarray in java using jsonobject?
How to Create a Correct JSONArray in Java Using JSONObject?
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonArray.html
JsonArray (Java(TM) EE 7 Specification APIs)
JsonArray represents an immutable JSON array (an ordered sequence of zero or more values). It also provides an unmodifiable list view of the values in the array. A JsonArray object can be created by reading JSON data from an input source or it can be built from scratch using an array builder object.
🌐
LabEx
labex.io › tutorials › java-how-to-create-json-arrays-420797
How to create JSON arrays | LabEx
Learn efficient Java techniques for creating and manipulating JSON arrays with practical examples and methods for modern software development
🌐
Stleary
stleary.github.io › JSON-java › org › json › JSONArray.html
JSONArray
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.
🌐
Kodejava
kodejava.org › how-do-i-create-jsonarray-object
How do I create JSONArray object? - Learn Java by Examples
The following example show you ... jsonArray.put("Go"); System.out.println(jsonArray); // Create JSONArray from a string wrapped in bracket and // the values separated by comma....
🌐
Attacomsian
attacomsian.com › blog › jackson-create-json-array
How to create a JSON array using Jackson
October 14, 2022 - The following example demonstrates how you can use the ObjectMapper class to produce a JSON array: try { // create `ObjectMapper` instance ObjectMapper mapper = new ObjectMapper(); // create three JSON objects ObjectNode user1 = mapper.createObjectNode(); user1.put("id", 1); user1.put("name", "John Doe"); ObjectNode user2 = mapper.createObjectNode(); user2.put("id", 2); user2.put("name", "Tom Doe"); ObjectNode user3 = mapper.createObjectNode(); user3.put("id", 3); user3.put("name", "Emma Doe"); // create `ArrayNode` object ArrayNode arrayNode = mapper.createArrayNode(); // add JSON users to ar
Find elsewhere
🌐
Tabnine
tabnine.com › home page › code › java › org.json.jsonarray
org.json.JSONArray java code examples | Tabnine
HttpClient httpclient = new ... while ((line = reader.readLine()) != null) { sb.append(line + "\n"); JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++){ JSONObject json_data = jArray.getJSON...
🌐
TutorialsPoint
tutorialspoint.com › how-to-create-a-json-array-using-object-model-in-java
How to create a JSON Array using Object Model in Java?
import java.io.*; import javax.json.*; import javax.json.JsonObjectBuilder; public class JsonArrayTest { public static void main(String[] args) { JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add("Name", "Raja Ramesh"); builder.add("Designation", "Java Developer"); builder.add("Company", "TutorialsPoint"); JsonArray contactInfo = Json.createArrayBuilder().add(Json.createObjectBuilder().add("email", "raja@gmail.com")).add(Json.createObjectBuilder().add("mobile", "9959984000")).build(); builder.add("contactInfo", contactInfo); JsonObject data = builder.build(); StringWriter sw = new StringWriter(); JsonWriter jw = Json.createWriter(sw); jw.writeObject(data); jw.close(); System.out.println(sw.toString()); } }
🌐
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\"]";
🌐
JanBask Training
janbasktraining.com › community › java › how-to-create-correct-jsonarray-in-java-using-jsonobject
How to create correct JSONArray in Java using JSONObject | JanBask Training Community
November 2, 2025 - JSONObject obj1 = new JSONObject(); obj1.put("id", 1); obj1.put("name", "Alice"); JSONObject obj2 = new JSONObject(); obj2.put("id", 2); obj2.put("name", "Bob"); ... You can loop through data and dynamically put objects into the array.
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonArrayBuilder.html
JsonArrayBuilder (Java(TM) EE 7 Specification APIs)
A builder for creating JsonArray models from scratch. This interface initializes an empty JSON array model and provides methods to add values to the array model and to return the resulting array.
🌐
Javatpoint
javatpoint.com › json-array
JSON Array - javatpoint
JSON Array for beginners and professionals with examples of JSON with java, json array of string, json array of numbers, json array of booleans, json srray of objects, json multidimentional array. Learn JSON array example with object, array, schema, encode, decode, file, date etc.
🌐
W3Docs
w3docs.com › java
How to create correct JSONArray in Java using JSONObject
import org.json.JSONArray; public class Main { public static void main(String[] args) { JSONArray array = new JSONArray(); array.put(1); array.put(2); array.put(3); System.out.println(array.toString()); } }
🌐
Medium
medium.com › @Mohd_Aamir_17 › mastering-json-in-java-a-comprehensive-guide-to-handling-json-objects-arrays-and-nodes-with-df57bf0ebff1
Mastering JSON in Java: A Comprehensive Guide to Handling JSON Objects, Arrays, and Nodes with Jackson | by Mohd Aamir | Medium
November 4, 2024 - Whether you’re developing REST APIs, handling data transformation, or integrating with third-party services, understanding how to handle JSON data efficiently in Java is crucial. This article offers an in-depth look at how to parse, create, and manipulate JSON objects, arrays, and nodes using the Jackson library, covering advanced scenarios to equip you with the tools to tackle complex JSON data in Java.
🌐
IBM
ibm.com › support › pages › creating-json-string-json-object-and-json-arrays-automation-scripts
Creating a JSON String from JSON Object and JSON Arrays in Automation Scripts
# creating a JSON String with an array (directly executed via Run Automation Script button) from com.ibm.json.java import JSONObject, JSONArray from sys import * # method for creating a JSON formatted String including an array within def createJSONstring(): # defining the first child object ch1_obj = JSONObject() ch1_obj.put('CH_FIELD_1', 1) ch1_obj.put('CH_FIELD_2', 'VALUE_2') # defining the second child object ch2_obj = JSONObject() ch2_obj.put('CH_FIELD_1', 2) ch2_obj.put('CH_FIELD_2', 'VALUE_3') # adding child objects to children array ch_arr = JSONArray() ch_arr.add(ch1_obj) ch_arr.add(ch
🌐
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.
🌐
Couchbase
docs.couchbase.com › sdk-api › couchbase-java-client › com › couchbase › client › java › json › JsonArray.html
JsonArray (Couchbase Java SDK 3.11.1 API)
Static method to create a JsonArray from a JSON String. Not to be confused with from(Object...) from(aString)} which will populate a new array with the string. The string is expected to be a valid JSON array representation (eg.