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 ...
๐ŸŒ
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 ...
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
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(); } } }
๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ convert-list-to-json-java-objectmapper
Converting a List to JSON in Java using ObjectMapper โ€” javathinking.com
Finally, we use the writeValueAsString() method to convert the list to a JSON string and print it. If your Java class does not have getters for its fields, ObjectMapper will not be able to access the values, and the resulting JSON will have ...
๐ŸŒ
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...