How to Convert an ArrayList into a JSON String in Java? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In Java, an ArrayList is a resizable array implementation of the List interface. It implements the List interface and is the most commonly used implementation of List. In this article, we will learn how to convert an ArrayList into a JSON string in Java. Steps to convert an ArrayList into a JSON string in JavaBelow are the steps and implementation of converting an ArrayList into a JSON string with Jackson. Step 1: Create a Maven ProjectOpen any preferred IDE and create a new Maven project. Here we are using IntelliJ IDEA, so, we can do this by selecting File -> New -> Project.. -> Maven and following the wizard. Project Structure:Below is the project structure that we have created. projectStep 2: Add Jackson Dependency to pom.xmlNow, we will add Jackson dependency to pom.xml file. XML <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>ArrayList</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.12.5</version> <!-- Replace with the latest version --> </dependency> </dependencies> <properties> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> </project> Step 3: Add logic of converting an ArrayList into a JSON string Here we are adding the logic of converting an ArrayList into a JSON string of Java in the main class. Java package org.example; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; public class Main { public static void main(String[] args) { // Create an ArrayList ArrayList<String> courses = new ArrayList<>(); courses.add("Java"); courses.add("Python"); courses.add("C++"); // Convert ArrayList to JSON string ObjectMapper objectMapper = new ObjectMapper(); try { String jsonString = objectMapper.writeValueAsString(courses); // Print JSON string System.out.println(jsonString); } catch (JsonProcessingException e) { e.printStackTrace(); } } } Output: Explanation of the above Program: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.It catches any exceptions that may occur during the JSON conversion.It prints out the JSON string representation of the ArrayList to the console. Comment More infoAdvertise with us Next Article How to Convert an ArrayList into a JSON String in Java? P pranay0911 Follow Improve Article Tags : Java Java Programs Java-ArrayList JSON Java-JSON Java Examples +2 More Practice Tags : Java Similar Reads How to Convert a Comma-Separated String into an ArrayList in Java? In Java, to convert a comma-separated string into ArrayList, we can use the split() method to break the string into an array based on the comma delimiter. Another method we can also use Java Streams for a functional approach to achieve the same result.Example:Input: "Hello,from,geeks,for,geeks"Outpu 2 min read How to Convert a String to ArrayList in Java? Converting String to ArrayList means each character of the string is added as a separator character element in the ArrayList. Example: Input: 0001 Output: 0 0 0 1 Input: Geeks Output: G e e k s We can easily convert String to ArrayList in Java using the split() method and regular expression. Paramet 1 min read How to Convert JSON Array to String Array in Java? JSON stands for JavaScript Object Notation. It is one of the widely used formats to exchange data by web applications. JSON arrays are almost the same as arrays in JavaScript. They can be understood as a collection of data (strings, numbers, booleans) in an indexed manner. Given a JSON array, we wil 3 min read How to Convert a Vector of Objects into a JSON Array in Java? In Java, the conversion of data structures like Vector to JSON (JavaScript Object Notation) format is required especially while working with the APIs or data interchange between different systems. The conversion of the Vector of an Object to the JSON Array has various approaches that we will learn i 3 min read How to Convert an ArrayList of Objects to a JSON Array in Java? In Java, an ArrayList is a resizable array implementation of the List interface. It implements the List interface and is the most commonly used implementation of List. In this article, we will learn how to convert an ArrayList of objects to a JSON array in Java. Steps to Convert an ArrayList of Obje 3 min read How to Convert TreeMap to an ArrayList in Java? TreeMap is a part of the Java Collection framework. Java TreeMap contains values based on the key. It implements the NavigableMap interface and extends AbstractMap class. It provides an efficient means of storing key-value pairs in sorted order. Java TreeMap contains only unique elements. It cannot 4 min read How to Convert a String to a Character in Java? String and char are fundamental and most commonly used datatypes in Java. A String is not a primitive data type like char. To convert a String to char in Java, we have to perform character-based operations or have to process individual characters.In this article, we will learn how to convert a Strin 3 min read How to Convert a LinkedHashSet into an Array and List in Java? In Java, LinkedHashSet is a predefined class of Java that extends the HashSet and it implements the Set interface. It can be used to implement the doubly linked list of the elements in the set, and it provides the predictable iteration order. In this article, we will learn how to convert a LinkedHas 3 min read Java Program to Convert an Array into a List In Java, arrays and lists are two commonly used data structures. While arrays have a fixed size and are simple to use, lists are dynamic and provide more flexibility. There are times when you may need to convert an array into a list, for instance, when you want to perform operations like adding or r 4 min read How to Get Substring Items Within Arraylist in Java? In Java, ArrayList is the pre-defined class of the Java collection framework, and it is part of java.util package. ArrayList can be used to add or remove an element dynamically in a Java program. It can be dynamically based on the elements added or removed from the ArrayList. In this article, we wil 2 min read Like