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 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. Here’s an example:
Discussions

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
Spring Boot - make json conversion use float[] instead of List<Double>
My initial answer (more digging possible later) is “no, you can’t.” Or at least, no you can’t the way you are doing it. You are deserializing to Map. The deserializer gets to pick everything then. To do more, you start needing to have a target object to deserialize to instead. You can write your own custom deserializer and go from there: https://www.baeldung.com/jackson-deserialization and http://tutorials.jenkov.com/java-json/jackson-objectmapper.html#custom-deserializer go into that. That said, I have to ask why you want a float array instead? More on reddit.com
🌐 r/javahelp
3
3
September 11, 2018
How to turn json objects into an array of json objects using 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
7
4
June 28, 2022
🌐
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 - Next, we will convert the list to a JSON array using the valueToTree() method of ObjectMapper.
🌐
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.
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(); } } }
🌐
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.
🌐
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 ... 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 ...
🌐
Java Guides
javaguides.net › 2019 › 07 › convert-list-to-json-array-using-jackson.html
Convert List to JSON Array Using Jackson
July 21, 2019 - Jackson - Convert Java Object to/from JSON Example (popular) Jackson - List, Set, and Map Serialization and Deserialization in Java Examples
🌐
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 empty values or be missing fields. For example, if we remove the getName() and getAge() methods from the Person class in the previous example, the JSON output will be [{"name":null,"age":0},{"name":null,"age":0}].
🌐
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 - 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, ...
🌐
Baeldung
baeldung.com › home › json › jackson › convert json array to java list
Convert JSON Array to Java List | Baeldung
August 13, 2025 - Learn how to convert a JSON array to a Java List using the popular Gson and Jackson libraries.
🌐
TutorialsPoint
tutorialspoint.com › how-can-we-convert-a-json-array-to-a-list-using-jackson-in-java
How can we convert a JSON array to a list using Jackson in Java?\\n
June 5, 2025 - import com.fasterxml.jackson.c...ne","age":25}]"; ObjectMapper objectMapper = new ObjectMapper(); try { List<Person> personList = objectMapper.readValue(jsonArray, new TypeReference<List<Person>>(){}); for (Person person : personList) { System.out.println("Name: " + ...
🌐
Mkyong
mkyong.com › home › java › how to parse json array with jackson
How to parse JSON Array with Jackson - Mkyong.com
April 23, 2024 - This example converts a list of Person objects to a JSON string with the list labeled as "Person": JsonArrayToObjectExample3.java ·