The problem is not the JSONArray.toString(), as @Selvin mentioned.

From JSONArray source:

/**
 * Encodes this array as a compact JSON string, such as:
 * <pre>[94043,90210]</pre>
 */
@Override public String toString() {
    try {
        JSONStringer stringer = new JSONStringer();
        writeTo(stringer);
        return stringer.toString();
    } catch (JSONException e) {
        return null;
    }
}

/**
 * Encodes this array as a human readable JSON string for debugging, such
 * as:
 * <pre>
 * [
 *     94043,
 *     90210
 * ]</pre>
 *
 * @param indentSpaces the number of spaces to indent for each level of
 *     nesting.
 */
public String toString(int indentSpaces) throws JSONException {
    JSONStringer stringer = new JSONStringer(indentSpaces);
    writeTo(stringer);
    return stringer.toString();
}

The problem is that you need to convert your ChecklistAnswer to JSON object first for your JSONArray to work properly.

Again from Javadoc:

/**
 * A dense indexed sequence of values. Values may be any mix of
 * {@link JSONObject JSONObjects}, other {@link JSONArray JSONArrays}, Strings,
 * Booleans, Integers, Longs, Doubles, {@code null} or {@link JSONObject#NULL}.
 * Values may not be {@link Double#isNaN() NaNs}, {@link Double#isInfinite()
 * infinities}, or of any type not listed here.

...

Answer from Nemanja Maksimovic on Stack Overflow
🌐
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 - // importing the packages import java.util.*; import org.json.*; public class GFG { public static void main(String[] args) { // Initialising a JSON example array JSONArray exampleArray = new JSONArray(); // Entering the data into the array exampleArray.put("Geeks "); exampleArray.put("For "); exampleArray.put("Geeks "); // Printing the contents of JSON example array System.out.print("Given JSON array: " + exampleArray); System.out.print("\n"); // Creating example List and adding the data to it List<String> exampleList = new ArrayList<String>(); for (int i = 0; i < exampleArray.length; i++) { e
Top answer
1 of 6
2

The problem is not the JSONArray.toString(), as @Selvin mentioned.

From JSONArray source:

/**
 * Encodes this array as a compact JSON string, such as:
 * <pre>[94043,90210]</pre>
 */
@Override public String toString() {
    try {
        JSONStringer stringer = new JSONStringer();
        writeTo(stringer);
        return stringer.toString();
    } catch (JSONException e) {
        return null;
    }
}

/**
 * Encodes this array as a human readable JSON string for debugging, such
 * as:
 * <pre>
 * [
 *     94043,
 *     90210
 * ]</pre>
 *
 * @param indentSpaces the number of spaces to indent for each level of
 *     nesting.
 */
public String toString(int indentSpaces) throws JSONException {
    JSONStringer stringer = new JSONStringer(indentSpaces);
    writeTo(stringer);
    return stringer.toString();
}

The problem is that you need to convert your ChecklistAnswer to JSON object first for your JSONArray to work properly.

Again from Javadoc:

/**
 * A dense indexed sequence of values. Values may be any mix of
 * {@link JSONObject JSONObjects}, other {@link JSONArray JSONArrays}, Strings,
 * Booleans, Integers, Longs, Doubles, {@code null} or {@link JSONObject#NULL}.
 * Values may not be {@link Double#isNaN() NaNs}, {@link Double#isInfinite()
 * infinities}, or of any type not listed here.

...

2 of 6
1

In my ChecklistAnwer class i added:

   public JSONObject toJsonObject(){
    JSONObject json = new JSONObject();

    try {
        json.put("questionId", questionId);
        json.put("checklistId", checklistId);
        json.put("answer", answer);
        json.put("remark", remark);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return json;
}

and in my other class:

JSONArray answers = new JSONArray();

ChecklistAnswer answer = new ChecklistAnswer(questions.get(id).id, 2, cb.isChecked(),         text.getText().toString());

answers.put(answer.toJsonObject());

if i filled the array:

String js = answers.toString(1);

and that returns:

[
 {
  "answer": true,
  "questionId": 1,
  "remark": "",
  "checklistId": 2
 },
 {
  "answer": false,
  "questionId": 4,
  "remark": "teesxfgtfghyfj",
  "checklistId": 2
 },
 {
  "answer": true,
  "questionId": 4,
  "remark": "",
  "checklistId": 2
 },
 {
  "answer": true,
  "questionId": 4,
  "remark": "",
  "checklistId": 2
 },
 {
  "answer": true,
  "questionId": 4,
  "remark": "",
  "checklistId": 2
 },
 {
  "answer": true,
  "questionId": 4,
  "remark": "",
  "checklistId": 2
 },
 {
  "answer": true,
  "questionId": 4,
  "remark": "",
  "checklistId": 2
 }
]

thanks to @Selvin

🌐
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.
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › how-can-we-convert-a-jsonarray-to-string-array-in-java
How can we convert a JSONArray to String Array in Java?
June 6, 2025 - HR Interview Questions · Computer Glossary · Who is Who · JavaJSONObject Oriented ProgrammingProgramming · A JSONArray is a class provided by the org.json package that represents a collection of JSON values. These values can be of any type, such as strings, numbers, booleans, or even nested objects or arrays. If you do not know what JSON is, then you can read the JSON tutorial. We can convert a JSONArray to String Array by using a simple loop as shown in the example below - import org.json.*; import java.util.*; public class JsonArraytoStringArrayTest { public static void main(String[] arg
🌐
Tabnine
tabnine.com › home page › code › java › org.json.jsonarray
org.json.JSONArray.toString java code examples | Tabnine
@Override public <T> void addPolyline(AirMapPolyline<T> polyline) { try { JSONArray array = new JSONArray(); for (LatLng point : polyline.getPoints()) { JSONObject json = new JSONObject(); json.put("lat", point.latitude); json.put("lng", point.longitude); array.put(json); } webView.loadUrl(String.format( "javascript:addPolyline(" + array.toString() + ", %1$d, %2$d, %3$d);", polyline.getId(), polyline.getStrokeWidth(), polyline.getStrokeColor())); } catch (JSONException e) { Log.e(TAG, "error constructing polyline JSON", e); } }
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonArray.html
JsonArray (Java(TM) EE 7 Specification APIs)
JsonArray provides various accessor methods to access the values in an array. The following example shows how to obtain the home phone number "212 555-1234" from the array built in the previous example: JsonObject home = array.getJsonObject(0); String number = home.getString("number");
Find elsewhere
🌐
Google Groups
groups.google.com › g › vertx › c › 5fgz-e2rTbk
casting a JsonArray to a specific type
Also, if you're using Java 8 you can make the List to List<String> conversion a little prettier with the stream API. Something like... List<String> list = array.toList().stream().collect(Collectors.mapping(value -> value.toString()), Collectors::toList); Might have that a little wrong since I typed that from my phone :-) On Dec 28, 2014, at 3:23 PM, Alexander Lehmann <alex...@gmail.com> wrote: I wonder if there is a smarter way to cast a JsonArray to a List of specific type.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Converting a JSON Object to a JSON Array in Java - Java Code Geeks
August 1, 2025 - // JsonConversionExample.java import org.json.JSONArray; import org.json.JSONObject; public class JsonConversionExample { public static void main(String[] args) { String jsonString = "{ \"apple\": 1, \"banana\": 2, \"cherry\": 3 }"; JSONObject jsonObject = new JSONObject(jsonString); JSONArray jsonArray = new JSONArray(jsonObject.toMap().values()); System.out.println("Converted JSON Array:"); System.out.println(jsonArray.toString(2)); } }
🌐
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 - @Test public void given_JavaLi... passing the articles List as a parameter. The JSONArray class provides a toString() method to obtain the JSON array as a string representation....
🌐
TutorialsPoint
tutorialspoint.com › how-can-we-convert-a-json-string-to-a-json-object-in-java
How can we convert a JSON string to a JSON object in Java?
July 3, 2020 - import org.json.JSONObject; import org.json.JSONArray; public class StringToJSONTest { public static void main(String args[]) { String str = "[{\"No\":\"1\",\"Name\":\"Adithya\"},{\"No\":\"2\",\"Name\":\"Jai\"}, {\"No\":\"3\",\"Name\":\"Raja\"}]"; JSONArray array = new JSONArray(str); for(int i=0; i < array.length(); i++) { JSONObject object = array.getJSONObject(i); System.out.println(object.getString("No")); System.out.println(object.getString("Name")); } } } ... import org.json.*; public class StringToJsonObjectTest { public static void main(String[] args) { String str = "{\"name\": \"Raja\", \"technology\": \"Java\"}"; JSONObject json = new JSONObject(str); System.out.println(json.toString()); String tech = json.getString("technology"); System.out.println(tech); } }
🌐
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
The second exercise is more interesting since we will use both JSONObject and JSONArray in order to send a parent record together with its two child records. Below, you can see the code piece for this task: # 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 t
🌐
freeCodeCamp
freecodecamp.org › news › jsonobject-tostring-how-to-convert-json-to-a-string-in-java
JSONObject.toString() – How to Convert JSON to a String in Java
April 14, 2023 - In Java, the JSONObject class provided by the org.json package is commonly used to create and manipulate JSON objects. The JSONObject.toString() method is a useful method provided by this class that converts a JSON object to a string representation.
🌐
Apache
sling.apache.org › apidocs › sling7 › org › apache › sling › commons › json › JSONArray.html
JSONArray (Apache Sling 7 API)
The internal form is an object ... The values can be any of these types: Boolean, JSONArray, JSONObject, Number, String, or the JSONObject.NULL object. The constructor can convert a JSON text into a Java object. The toString method converts to JSON text....
🌐
Esri Developer
developers.arcgis.com › enterprise-sdk › api-reference › java › com › esri › arcgis › server › json › JSONArray.html
JSONArray (ArcObjects Java API)
The internal form is an object ... The values can be any of these types: Boolean, JSONArray, JSONObject, Number, String, or the JSONObject.NULL object. The constructor can convert a JSON text into a Java object. The toString method converts to JSON text....