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
🌐
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.
Discussions

How to create correct JSONArray in Java using JSONObject
What is the correct structure and approach to combine multiple JSON objects into a well-formed JSON array? Log in to share your answer and help other learners. Log in to answer ... To correctly create a JSONArray in Java using JSONObject, you need to follow a structured approach: first build ... More on janbasktraining.com
🌐 janbasktraining.com
2
November 2, 2025
New to Java, wanted some help with reading .json object arrays.
it gives me an error What's the error? More on reddit.com
🌐 r/javahelp
11
1
February 25, 2024
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
using JSONArray, JSONObject etc. to parse JSON with Java
I'd highly advise you to use the ObjectMapper instead of JSONArray and JSONObject. Try to mimic the json objects structure with a class, create 0 field and all argument contrstructors, getters and setters and simply use new ObjectMapper().readValue(yourJsonString, YouMappedObject.class) More on reddit.com
🌐 r/javahelp
6
5
May 22, 2022
🌐
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.
🌐
GitHub
github.com › stleary › JSON-java › blob › master › Examples.md
JSON-java/Examples.md at master · stleary/JSON-java
Imports used in the examples: import ... "]"; //Then, we initializate the JSONArray thanks to its constructor JSONArray array = new JSONArray(arrayStr); System.out.println("Values array: "+ array); //We convert that array into ...
🌐
ReqBin
reqbin.com › json › java › uzykkick › json-array-example
Java | What is JSON Array?
June 11, 2022 - You can use the "[]" operator to get an array at any index and use the "[]" operator again to get an element of the selected array. The following is an example of creating a multidimensional JSON array: ... The mixed JSON array contains various types of elements. Below is an example of a JSON array that stores mixed values: ... Convert your JSON Array request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the Java code generator.
🌐
TutorialsPoint
tutorialspoint.com › how-to-write-create-a-json-array-using-java
How to Write/create a JSON array using Java?
HR Interview Questions · Computer Glossary · Who is Who · Java Object Oriented Programming Programming · A JSON array is an ordered collection of values that are enclosed in square brackets i.e., it begins with '[' and ends with ']'. The values in the arrays are separated by ',' (comma).
🌐
TutorialsPoint
tutorialspoint.com › how-to-read-parse-json-array-using-java
How to read/parse JSON array using Java?
May 5, 2025 - Instantiate the JSONParser class of the json-simple library: ... 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.
Find elsewhere
🌐
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 - In essence, ArrayNode is suitable for structured JSON arrays, while JsonNode is ideal for complex, dynamic JSON processing. One of Jackson’s strongest features is its ability to easily convert JSON data into Java objects, and vice versa.
🌐
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.
🌐
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 - 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 ...
🌐
Crunchify
crunchify.com › json tutorials › how to parse jsonobject and jsonarrays in java? beginner’s guide
How to Parse JSONObject and JSONArrays in Java? Beginner's Guide • Crunchify
February 2, 2023 - Here is a simple Java tutorial which demonstrate how to parse JSONObject and JSONArrays in Java. JSON syntax is a subset of the JavaScript object notation
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Converting a JSON Object to a JSON Array in Java - Java Code Geeks
August 1, 2025 - This Java code demonstrates how to convert a JSON object into a JSON array of key-value pair objects using the org.json library. It begins by defining a JSON string containing fruit names as keys and their quantities as values. This string is parsed into a JSONObject.
🌐
LabEx
labex.io › tutorials › java-how-to-create-json-arrays-420797
How to create JSON arrays | LabEx
Whether you're working with web services, data exchange, or configuration management, understanding JSON array creation is crucial for modern Java programming. A JSON array is an ordered collection of values that can contain multiple data types, including strings, numbers, objects, or even nested arrays.
🌐
Android Developers
developer.android.com › api reference › jsonarray
JSONArray | API reference | Android Developers
August 3, 2026 - Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java | Baeldung
June 20, 2025 - CDL – a tool that provides methods to convert comma-delimited text into a JSONArray and vice versa · Cookie – converts from JSON String to cookies and vice versa · HTTP – used to convert from JSON String to HTTP headers and vice versa · JSONException – a standard exception thrown by this library · A JSONObject is an unordered collection of key and value pairs, resembling Java’s native Map implementations.
🌐
Attacomsian
attacomsian.com › blog › jackson-create-json-array
How to create a JSON array using Jackson
October 14, 2022 - The above code will generate the following JSON array: [ { "name" : "Ford", "models" : [ "Fiesta", "Focus", "Mustang" ] }, { "name" : "BMW", "models" : [ "320", "X3", "X5" ] }, { "name" : "Fiat", "models" : [ "500", "Panda" ] } ] For more Jackson ...
🌐
YouTube
youtube.com › watch
36. Create Simple JSON Arrays Payload Using Java List - YouTube
We need to create a dynamic JSON payload for API requests. We will learn to create a simple JSON object using Java List and how to use that in Rest Assured. ...
Published: May 22, 2021
🌐
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 - Now, we will add the logic to convert JSON Array Object to Java Object in the main class. ... package org.example; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { public static void main(String[] args) { try { // JSON string representing an array of user objects String jsonString = "[{\"firstName\":\"User1\",\"lastName\":\"XYZ\",\"email\":\"user1@example.com\"}," + "{\"firstName\":\"User2\",\"lastName\":\"PQR\",\"email\":\"user2@example.com\"}]"; // Create an ObjectMapper instance ObjectMapper objectMapper = new ObjectMapper(); // Deserialize the JSON string into an arr
🌐
GitHub
github.com › stleary › JSON-java › blob › master › src › main › java › org › json › JSONArray.java
JSON-java/src/main/java/org/json/JSONArray.java at master · stleary/JSON-java
import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; · · /** * A JSONArray is an ordered sequence of values. Its external text form is a · * string wrapped in square brackets with commas separating the values.
Author: stleary
🌐
Intellipaat
intellipaat.com › home › blog › how to create a correct jsonarray in java using jsonobject?
How to Create a Correct JSONArray in Java Using JSONObject?
May 27, 2025 - On the other hand, a JSON array is an ordered list of values. These values could be strings, numbers, booleans, JSON objects, or other arrays. It’s denoted as a list enclosed in square brackets []. To work with JSON in Java, include the org.json library either in your Maven or Gradle project.