CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > How to > How to Convert JSON Array to Java List (With Examples)

How to Convert JSON Array to Java List (With Examples)

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 6, 2026 · 4 min read · 0 Comments
Share: in X

Working with JSON is a common task in modern Java development, especially when dealing with APIs and external data sources. A typical use case involves converting a JSON array (e.g., from a REST API response) into a Java List for further processing.

In this tutorial, we’ll explore multiple ways to convert a JSON array to a Java List, including a detailed section with examples to convert JSON array to Java List using popular libraries such as Jackson, Gson, and org.json. We’ll also discuss when to use each method with example code.

Table of Contents

  • 1. What is a JSON Array?
  • 2. Create a Java Model Class
  • 3. Convert JSON Array to Java List Using Jackson
    • Why Use Jackson?
  • 4. Convert JSON Array to Java List Using Gson
    • Why Use Gson?
  • 5. Convert JSON Array to Java List Using org.json
    • Why Use org.json?
  • 6. Conclusion
    • Final Thoughts

1. What is a JSON Array?

A JSON array is an ordered list of values enclosed in square brackets ([]). These values can be strings, numbers, objects, or even other arrays.

For example:

[
  {"id": 1, "name": "Radha"},
  {"id": 2, "name": "Krishnan"},
  {"id": 3, "name": "Shyam"}
]

Our goal is to convert this JSON array into a Java List of objects (e.g., List<User>).

2. Create a Java Model Class

Before parsing, let’s define a simple model class:

public class User {
    private int id;
    private String name;

    // Getters and Setters
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    @Override
    public String toString() {
        return "User{id=" + id + ", name='" + name + "'}";
    }
}

3. Convert JSON Array to Java List Using Jackson

Jackson is one of the most popular libraries for JSON parsing in Java. It provides the ObjectMapper class, which makes JSON serialization and deserialization simple.

🔹 Example Code:

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.List;

public class JacksonExample {
    public static void main(String[] args) throws IOException {
        String jsonArray = "[{\"id\":1,\"name\":\"Radha\"},{\"id\":2,\"name\":\"Krishnan\"}]";

        ObjectMapper mapper = new ObjectMapper();

        List<User> users = mapper.readValue(jsonArray, new TypeReference<List<User>>() {});

        users.forEach(System.out::println);
    }
}

Output:

User{id=1, name='Radha'}
User{id=2, name='Krishnan'}

Why Use Jackson?

  • Easy to use and well-documented
  • Supports advanced features like annotations
  • Great for large-scale Spring Boot applications

4. Convert JSON Array to Java List Using Gson

Gson (by Google) is another lightweight and popular library for JSON operations in Java.

🔹 Example Code:

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.List;

public class GsonExample {
    public static void main(String[] args) {
        String jsonArray = "[{\"id\":1,\"name\":\"Radha\"},{\"id\":2,\"name\":\"Krishnan\"}]";

        Gson gson = new Gson();

        Type listType = new TypeToken<List<User>>() {}.getType();
        List<User> users = gson.fromJson(jsonArray, listType);

        users.forEach(System.out::println);
    }
}

Output:

User{id=1, name='Radha'}
User{id=2, name='Krishnan'}

Why Use Gson?

  • Simple and fast for basic use cases
  • Perfect for Android apps or lightweight Java projects

5. Convert JSON Array to Java List Using org.json

The org.json library provides a JSONArray class for manual JSON parsing. Though it’s not as elegant as Jackson or Gson, it can be useful in small projects or legacy systems.

🔹 Example Code:

import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;

public class OrgJsonExample {
    public static void main(String[] args) {
        String jsonArray = "[{\"id\":1,\"name\":\"Radha\"},{\"id\":2,\"name\":\"Krishnan\"}]";

        JSONArray array = new JSONArray(jsonArray);
        List<User> users = new ArrayList<>();

        for (int i = 0; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            User user = new User();
            user.setId(obj.getInt("id"));
            user.setName(obj.getString("name"));
            users.add(user);
        }

        users.forEach(System.out::println);
    }
}

Output:

User{id=1, name='Radha'}
User{id=2, name='Krishnan'}

Why Use org.json?

  • Good for small projects or when working without external dependencies
  • Offers low-level JSON manipulation control

6. Conclusion

Converting a JSON array to a Java List is straightforward with modern JSON libraries. Here’s a quick comparison:

LibraryCode SimplicityRecommended For
Jackson⭐⭐⭐⭐⭐Spring Boot, enterprise apps
Gson⭐⭐⭐⭐Android, lightweight apps
org.json⭐⭐Simple or legacy codebases

Final Thoughts

If you’re working with Spring Boot or enterprise-level applications, Jackson is the best choice. For simpler use cases or Android apps, Gson works great.

Related Posts:

  • (Solved) Java 8 date/time types are not supported by default
  • Java JSON Serialization and Deserialization
  • Spring Data REST example.
  • Control Statements in Java
  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
  • A Brief History Of Java
Tags:how-tojavajson
Was this article helpful?
← Previous ArticleConfigure CORS in Spring Cloud Gateway (WebFlux & WebMVC)
Next Article →How to Connect Java Application to a Remote Database Using an SSH Tunnel (with Spring Boot Examples)

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap