How to Convert an ArrayList into a JSON String in Java? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share 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 Like