Use GSON library for that. Here is the sample code

List<String> foo = new ArrayList<String>();
foo.add("A");
foo.add("B");
foo.add("C");

String json = new Gson().toJson(foo );

Here is the maven dependency for Gson

<dependencies>
    <!--  Gson: Java to Json conversion -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.2</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

Or you can directly download jar from here and put it in your class path

http://code.google.com/p/google-gson/downloads/detail?name=gson-1.0.jar&can=4&q=

To send Json to client you can use spring or in simple servlet add this code

response.getWriter().write(json);

Answer from code_fish 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 provided code snippet, we instantiate the ObjectMapper class and utilize its writeValueAsString() method. This method allows us to convert the articles List into a JSON array, which is then represented as a string.
๐ŸŒ
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...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ convert-an-arraylist-into-a-json-string-in-java
How to Convert an ArrayList into a JSON String in Java? - GeeksforGeeks
July 23, 2025 - It creates an ArrayList of type String and adds 3 course names to it. It uses the ObjectMapper from Jackson to convert the ArrayList to a JSON string.
๐ŸŒ
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]
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-convert-a-list-to-json-array-using-the-jackson-library-in-java
How to convert a List to JSON array using the Jackson library in Java?
April 29, 2025 - The writeValueAsString() method of the ObjectMapper class serializes a given Java object, such as a List or ArrayList, into JSON-formatted String.
Find elsewhere
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 713115 โ€บ java โ€บ conversion-array-list-Json-object
conversion of array list to Json object string (Java in General forum at Coderanch)
July 19, 2019 - programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums ยท this forum made possible by our volunteer staff, including ... ... Hi I have two lists Edge1List and Edge2List which I add to element on them. Edge1List:[o,p] and Edge2List: [p,null]. I convert Edge1List and Edge2List to JsonArray with the name of EdgeJsonArray1 and EdgeJsonArray2 respectively.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-convert-an-arraylist-of-objects-to-a-json-array-in-java
How to Convert an ArrayList of Objects to a JSON Array in Java? - GeeksforGeeks
July 23, 2025 - package org.example; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { // Create an ArrayList of objects List<Course> courses = new ArrayList<>(); courses.add( new Course(1, "Java", "25000", "3 Months")); courses.add( new Course(2, "C++", "20000", "3 Months")); // Convert the ArrayList to a JSON array ObjectMapper objectMapper = new ObjectMapper(); try { String jsonArray = objectMapper.writeValueAsString(courses); System.out.println(jsonArray); } catch (JsonProcessingException e) { e.printStackTrace(); } } }
๐ŸŒ
Java Tips
javatips.net โ€บ blog โ€บ convert-java-collection-list-string-array-into-json
Convert Java Collection / List / String[] Array Into JSON
April 30, 2016 - package net.javatips; import java.util.LinkedList; import java.util.List; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class Main { public static void main(String[] args) { // Configure gson GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); //Convert List of string into JSON List<String> strList = new LinkedList<String>(); strList.add("How"); strList.add("Are"); strList.add("You"); System.out.println("JSON String List "+gson.toJson(strList)); //Convert List of Object into JSON List<Student> studentList = new LinkedList<Student>(); Student
๐ŸŒ
Java Guides
javaguides.net โ€บ 2019 โ€บ 07 โ€บ convert-list-to-json-array-using-jackson.html
Convert List to JSON Array Using Jackson
July 21, 2019 - ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); List < String > progLangs = new ArrayList < > (); progLangs.add("C"); progLangs.add("C++"); progLangs.add("Java"); progLangs.add("Java EE"); progLangs.add("Python"); progLangs.add("Scala"); progLangs.add("JavaScript"); // Serialize Object to JSON.
๐ŸŒ
Adambien
adambien.blog โ€บ roller โ€บ abien โ€บ entry โ€บ list_string_to_jsonarray_conversion
List<String> to JsonArray Conversion with JSON-P and Java EE 8
January 10, 2019 - List<String> can be converted into JsonArray with: import javax.json.Json; import javax.json.JsonArray; import javax.json.stream.JsonCollectors; import org.junit.jupiter.api.Test; public class StringListToJsonArrayTest { @Test public void conversion() { JsonArray jsonStringArray = Arrays.asList("duke", "duchess").
๐ŸŒ
QA Automation Expert
qaautomation.expert โ€บ 2023 โ€บ 11 โ€บ 10 โ€บ how-to-convert-a-java-list-to-json-array-org-json
How to convert a Java list to JSON Array โ€“ org.json
November 8, 2023 - import org.json.JSONArray; import org.testng.annotations.Test; import java.util.Arrays; import java.util.List; public class ListToJsonObject { @Test public static void test() { List<String> list = Arrays.asList("Test 1", "Test 2", "Test 3", "Test 4"); System.out.println("List :" + list); JSONArray jsonArray = new JSONArray(list); System.out.println("Json Array :" + jsonArray); } }
๐ŸŒ
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 โ€บ 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. The Following is the code to convert a list of objects to JSON using the Gson library: import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.util.ArrayList; import java.util.List; public class ListToJson { 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 GsonBuilder().setPrettyPrinting().create(); // Convert the list to JSON String json = gson.toJson(personList); // Print the JSON string System.out.println(json); } }