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
Discussions

Convert List<Integer> to JSON in Java - Stack Overflow
How can I convert a List object in Java to a JSON object? More on stackoverflow.com
🌐 stackoverflow.com
Solved: Converting list to JSON object
Solved: I have a variable ( mylist ) with list such as 50810, 50811 which is populated from a web request. I was able to convert it into an array More on community.atlassian.com
🌐 community.atlassian.com
December 5, 2023
How to convert List <JSONObject> to Json String in java (com.amazonaws.util.json.JSONObject) - Stack Overflow
If you are using Amazon AWS's JSONObject, you should also include relevant import statements, as most readers (including me) will otherwise assume that you are using org.json classes. ... Save this answer. ... Show activity on this post. You should convert your list to a JSON Array, and just ... More on stackoverflow.com
🌐 stackoverflow.com
How do I save an ArrayList<(Custom object here)> with JSON?
Gson gson = new Gson(); String jsonAsString = gson.toJson(arrayList); This doesn't make a JSON object, just a string in JSON format. Easier to keep up with (e.g. saving it in SharedPreferences). And to deserialize it from JSON... Type type = new TypeToken>(){}.getType(); ArrayList courses = gson.fromJson(jsonAsString, type); The GSON library is really one of the more useful tools Google has for this purpose. More on reddit.com
🌐 r/androiddev
15
3
July 21, 2014
🌐
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 addition to external libraries like Gson and Jackson, Java also provides a built-in library called org.json for JSON processing. To convert a Java List to a JSON array using org.json, we can use the JSONArray class to accomplish this task.
🌐
TutorialsPoint
tutorialspoint.com › how-can-we-convert-a-list-to-the-json-array-in-java
How to convert a List to JSON array using the Jackson library in Java?
April 22, 2025 - In Jackson library, the createArrayNode() method is used to manually create a JSON array without converting an existing list. It allows you to build a JSON array node-by-node using the ArrayNode class. import java.util.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.node.ArrayNode; public class ListToJSONArrayUsingArrayNode { public static void main(String[] args) { List < String > list = Arrays.asList("JAVA", "PYTHON", "SCALA", ".NET", "TESTING"); ObjectMapper objectMapper = new ObjectMapper(); ArrayNode arrayNode = objectMapper.createArrayNode(); for (String item: list) { arrayNode.add(item); // adding each item manually } try { String jsonArray = objectMapper.writeValueAsString(arrayNode); System.out.println(jsonArray); } catch (Exception e) { e.printStackTrace(); } } }
🌐
Quora
quora.com › How-do-I-convert-a-list-to-JSON-in-Java
How to convert a list to JSON in Java - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Java Guides
javaguides.net › 2019 › 07 › convert-list-to-json-array-using-jackson.html
Convert List to JSON Array Using Jackson
July 21, 2019 - In this quick article, I will show how to convert a List to JSON array using Jackson. Check out complete Jackson tutorial at Java Jackson JSON Tutorial with Examples. We are using Jackson library to convert Java List to JSON array so let's add below Jackson dependency to your project's classpath ...
🌐
GitHub
gist.github.com › sheharyarn › cba56ff154de2cc62fc5
Simple Java Class to convert Lists/Maps to JSON and vice versa · GitHub
Simple Java Class to convert Lists/Maps to JSON and vice versa · Raw · SimpleJSON.java · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Find elsewhere
🌐
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 - Here we are adding the logic of converting an ArrayList of objects to a JSON array of Java in the main class. ... 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(); } } }
🌐
DevGenius
blog.devgenius.io › how-to-convert-a-java-list-to-a-json-array-a-simple-guide-d3428951a488
How to Convert a Java List to a JSON Array: A Simple Guide | by M Business Solutions | Dev Genius
December 5, 2024 - Fortunately, converting a Java List to a JSON array is straightforward with the help of libraries like Jackson or Gson.
🌐
CodingTechRoom
codingtechroom.com › question › convert-list-to-json-java
How to Serialize a List to JSON in Java - CodingTechRoom
import com.google.gson.Gson; import ... "Sample output")); // Convert List to JSON Gson gson = new Gson(); String jsonOutput = gson.toJson(outputList); System.out.println(jsonOutput); // Outputs JSON representation of the list ...
🌐
YouTube
youtube.com › watch
How To Convert Java List Object Into JSON String using Jackson API | Java Inspires - YouTube
In this video, we will see how to convert(serialize) Java List Object into JSON String and vice versa means how to convert(deserialize) JSON String to Java ...
Published: June 7, 2021
🌐
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 - In this tutorial, we will convert a Java list into a JSON Object. Most of the times, the JSONs built in the organizations are complex. It contains string, int, list, arrays and soon. In this tutorial, we will use the below mentioned dependency. <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20230618</version> </dependency> Let us create a Java List. List<String> list = Arrays.asList("Test 1", "Test 2", "Test 3", "Test 4"); We want to convert this list in a JSON Object.
🌐
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
GSON Class
April 22, 2025 - package com.tutorialspoint; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class GsonTester { public static void main(String[] args) { String jsonString = "{\"name\":\"Mahesh\", \"age\":21}"; GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); Gson gson = builder.create(); Student student = gson.fromJson(jsonString, Student.class); System.out.println(student); jsonString = gson.toJson(student); System.out.println(jsonString); } } class Student { private String name; private int age; public Student(){} public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String toString() { return "Student [ name: "+name+", age: "+ age+ " ]"; } }
🌐
Atlassian Community
community.atlassian.com › q&a › atlassian automation › questions › converting list to json object
Solved: Converting list to JSON object
December 5, 2023 - I have a variable (mylist) with list such as 50810, 50811 which is populated from a web request. I was able to convert it into an array like ["50810", "50811"] using .asJsonStringArray Ultimately, I want to convert it into JSON object like [{ "mykey" : "50810"}, {"mykey" : "50811"}] so I can updat...
🌐
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 - You need to create separate instances of JSONObject for each edge, not reuse the same one for both.