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 - 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\"]";
๐ŸŒ
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]
๐ŸŒ
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 - I want to show that o from EdgeJsonArray1 is connect to p from EdgeJsonArray2 and p from EdgeJsonArray1 is connected to null from EdgeJsonArray2 which is I put them in a Jsonobject name as EdgeJsonObjsub with different key. The result that I obtained by running the program: {"Edges": [{ "Edge 1": { "From": "p", "to": "null" }, "Edge 0": { "From": "p", "to": "null" } }]} The expected result is: {"Edges": [{ "Edge 0": { "From": "o", "to": "p" }, "Edge 1": { "From": "p", "to": "null" } }]}
๐ŸŒ
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 - Then we will create a JSON array using the StringBuilder class. Next, we will iterate through the list and append each element to the JSON array. Finally, we will print the JSON array. Here is the code to convert a list to a JSON array manually: import java.util.Arrays; import java.util.List; ...
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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); } }
๐ŸŒ
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(); } } }
๐ŸŒ
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"). stream(). map(Json::createValue). collect(JsonCollectors.toJsonArray()); System.out.println(jsonStringArray); } }
๐ŸŒ
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 - ArrayNode: It is a special type of JsonNode used for handling JSON arrays, allows to create, add, and modify elements manually inside a JSON array structure. ... We are using the Jackson library to convert a Java List to a JSON array and if you're using Maven, we need to add Jackson dependency to your project's classpath or pom.xml.
๐ŸŒ
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); } }
๐ŸŒ
CodingTechRoom
codingtechroom.com โ€บ question โ€บ convert-list-data-to-json-java
How to Convert List Data to JSON Format in Java - CodingTechRoom
When handling data interchange between applications, JSON format is a common requirement. Java collections, such as List, need serialization for storage or transmission. Using Gson for conversion by creating a Gson object and calling `toJson()`.
๐ŸŒ
Code2care
code2care.org โ€บ java โ€บ convert-java-string-json-using-jackson
Convert Java List to Json String using Jackson | Code2care
September 19, 2022 - Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3 ... import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class JavaListToJsonString { public static void main(String[] args) { try { List<String> insuranceCompaniesList = new ArrayList<>(); insuranceCompaniesList.add("Chubb Ltd."); insuranceCompaniesList.add("Travelers Companies Inc."); insu