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 above test method, we create a Gson instance (gson) and then use the toJson() method to convert the articles List to a JSON array represented as a string. Finally, we utilize the Assert class to verify the equality of the output jsonArray ...
Discussions

How to convert list data into json in java - Stack Overflow
I have a function which is returning Data as List in java class. Now as per my need, I have to convert it into Json Format. Below is my function code snippet: public static List More on stackoverflow.com
🌐 stackoverflow.com
How to convert List to Json String in java (com.amazonaws.util.json.JSONObject) - Stack Overflow
@VinaySawant Right, ObjectMapper is for Java -> JSON objects. You can just use toString(), changed my answer. – Florian Albrecht Commented Apr 4, 2018 at 12:18 ... List jsons = new ArrayList<>(); jsons.add(new JSONObject(ImmutableMap.of("Attribute", "EmailAddress", "Value", "[email ... More on stackoverflow.com
🌐 stackoverflow.com
How to parse json to get size of the list using jsonObject in java?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
4
1
May 16, 2022
How to parse json to get size of the list from jsonObject using Java?
Google "How to parse JSON Java" will return plenty of guides - more useful and a larger resources then what a reddit comment can provide :) Most parsing libraries use common Java structures, so if the json object contains a list, then the list will most likely have a "size" method you can use. More on reddit.com
🌐 r/softwaretesting
20
2
May 16, 2022
🌐
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.
🌐
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 - Here is the code to convert a list to a JSON array manually: import java.util.Arrays; import java.util.List; public class ManualJsonArray { public static void main(String[] args) { List<String> list = Arrays.asList("apple", "banana", "cherry"); StringBuilder jsonArray = new StringBuilder("["); for (int i = 0; i < list.size(); i++) { jsonArray.append(""").append(list.get(i)).append("""); if (i < list.size() - 1) jsonArray.append(", "); } jsonArray.append("]"); System.out.println("JSON Array: " + jsonArray.toString()); } }
🌐
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 ...
Find elsewhere
🌐
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]
🌐
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.
🌐
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.
🌐
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 - Gson is a third-party Java library developed by Google. It is used for converting Java objects to JSON and vice versa. In the Gson library, we can convert a list of objects to JSON using the toJson() method.
🌐
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 - <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.
🌐
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(); } } }
🌐
Coderanch
coderanch.com › t › 643753 › java › Create-Json-List-data
Create Json from a List's data (EJB and other Jakarta /Java EE Technologies forum at Coderanch)
My first reaction was to iterate the Lists, after specifying an ArrayBuilder outside the loop, and add these objects. Problem is it doesn't work. Either I don't add the elements correctly or it doesn't write the output correctly. How would you write a similar Json iterating a List? Netbeans 11 - JavaEE ...
🌐
How to do in Java
howtodoinjava.com › home › convert json array to list: gson, jackson and org.json
Convert JSON Array to List: Gson, Jackson and Org.json
September 25, 2023 - In Java, due to type erasure, the generic type information of collections (like List<T>) is not available at runtime. So Gson doesn’t know the exact type we want to deserialize to when dealing with generic types. The TypeToken class retains this information and acts as a workaround for the limitations of type erasure. List<Person> readPersonListFromJsonArray(String jsonArray) { //Use autowired bean in Spring / Spring Boot Gson gson = new Gson(); Type listType = new TypeToken<List<Person>>() {}.getType(); List<Person> personList = gson.fromJson(jsonArray, listType); return personList; }
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Converting JSON Array to Java List with Gson - Java Code Geeks
April 25, 2024 - Then, we use Gson’s fromJson() method, passing the JSON string and the Type object, to deserialize the JSON array into a Java List.
🌐
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 ...