You should convert your list to a JSON Array, and just use its toString() function:

JSONArray myArray = new JSONArray(jsonObjlist);

// ...
String arrayToJson = myArray.toString(2);

The int parameter specifies the indent factor to use for formatting.

Answer from Florian Albrecht 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 - In the above code snippet, we create an instance of the JSONArray class, passing the articles List as a parameter. The JSONArray class provides a toString() method to obtain the JSON array as a string representation. In this article, we discussed converting a Java List to a JSON array as a common task in modern software development.
๐ŸŒ
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 - List<String> exampleList = new ArrayList<String>(); ... We can loop through the JSON array to add all elements to our List.
๐ŸŒ
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.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-can-we-convert-a-list-to-the-json-array-in-java
How can we convert a list to the JSON array in Java?
April 22, 2025 - We will use the toPrettyString() method to convert the JSON array to a string. Finally, we will print the JSON array. Following is the code to convert a list to a JSON array using the Jackson library: import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-convert-a-list-to-JSON-in-Java
How to convert a list to JSON in Java - Quora
Answer (1 of 8): Just use ObjectMapper from fasterxml library. [code]import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(anyObject); [/code]
Find elsewhere
๐ŸŒ
Java Tips
javatips.net โ€บ blog โ€บ convert-java-collection-list-string-array-into-json
Convert Java Collection / List / String[] Array Into JSON
April 30, 2016 - Here we are creating List of student objects and passing this list into gson.toJson() method, which will accept Collectin,List, String[] etc. package net.javatips; import java.util.LinkedList; import java.util.List; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class ...
๐ŸŒ
Makeinjava
makeinjava.com โ€บ home โ€บ convert list of objects to/from json in java (jackson objectmapper/ example)
Convert list of objects to/from JSON in java (jackson objectmapper/example)
January 1, 2024 - Convert list of user defined objects or POJOs to JSON String - jackson objectmapper in java. Transformed List collections to JSON String (maven dependency)
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ convert-a-list-of-objects-to-json-using-the-gson-library-in-java
Convert a list of objects to JSON using the Gson library in Java?
April 22, 2025 - Finally, we will print the JSON string. Let's see the code to convert a list of objects to JSON using toJsonTree() method: import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import java.util.ArrayList; import java.util.List; public class ListToJsonTree { public static void main(String[] args) { // Create a list of objects List<Person> personList = new ArrayList<>(); personList.add(new Person("Ansh", 23)); personList.add(new Person("Bam", 17)); personList.add(new Person("Ace", 22)); // Create a Gson instance Gson gson = new Gson(); // Convert the list to JSON array JsonElement jsonElement = gson.toJsonTree(personList); JsonArray jsonArray = jsonElement.getAsJsonArray(); // Convert the JSON array to string String jsonString = jsonArray.toString(); // Print the JSON string System.out.println(jsonString); } }
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ how to parse json array with jackson
How to parse JSON Array with Jackson - Mkyong.com
April 23, 2024 - This example converts a list of Person objects to a JSON string with the list labeled as "Person": JsonArrayToObjectExample3.java ยท
๐ŸŒ
CodingTechRoom
codingtechroom.com โ€บ question โ€บ convert-list-data-to-json-java
How to Convert List Data to JSON Format in Java - CodingTechRoom
import com.google.gson.Gson; import java.util.List; public class ListToJson { public static void main(String[] args) { List<String> list = Arrays.asList("apple", "banana", "orange"); Gson gson = new Gson(); String json = gson.toJson(list); System.out.println(json); } } // Output: ...
๐ŸŒ
Google Groups
groups.google.com โ€บ g โ€บ vertx โ€บ c โ€บ 5fgz-e2rTbk
casting a JsonArray to a specific type
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 ...