How to Convert JSON Array Object to Java Object?
Last Updated :
28 Apr, 2025
JSON arrays are useful for storing multiple values together that are related or part of the same set. For example, storing a list of items, user profiles, product catalog, etc. JSON arrays allow ordered access to the values using indices like in regular arrays in other languages (0 indexed).
Conversion Methods:
- Using a JSON parsing library: Jackson & GSON
- Iterating and parsing manually.
Steps to Convert JSON Array Object to Java Object
Below are the steps and implementation to convert JSON Array object to Java object using Jackson library.
Step 1: Create a Maven Project
Open any preferred IDE and create a new Maven project. Here we will be using IntelliJ IDEA, we can do this by selecting File -> New -> Project.. -> Maven and following the wizard.

Step 2: Add Jackson Dependency to POM.xml
Now, we will add Jackson dependency to the 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>Java-Object</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version> <!-- Use the latest version available -->
</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: Create the Java POJO Class
The User class defines a POJO to map JSON data with name and age properties. Getters and setters are provided for Jackson to populate objects.
User.java
Java
package org.example;
public class User
{
private String firstName;
private String lastName;
private String email;
public User() {}
// Constructor Declaration
public User(String firstName, String lastName,
String email)
{
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
// generate getters and setters
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
}
Step 4: In the Main class add logic of Conversion JSON Array Object to Java Object
Now, we will add the logic to convert JSON Array Object to Java Object in the main class.
Java
package org.example;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args)
{
try {
// JSON string representing an array of user objects
String jsonString = "[{\"firstName\":\"User1\",\"lastName\":\"XYZ\",\"email\":\"user1@example.com\"},"
+ "{\"firstName\":\"User2\",\"lastName\":\"PQR\",\"email\":\"user2@example.com\"}]";
// Create an ObjectMapper instance
ObjectMapper objectMapper = new ObjectMapper();
// Deserialize the JSON string into an array of User objects
User[] users = objectMapper.readValue(jsonString, User[].class);
// Print the details of each user
for (User user : users) {
System.out.println(
"First Name: " + user.getFirstName()
+ ", Last Name: " + user.getLastName()
+ ", Email: " + user.getEmail());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
First Name: User1, Last Name: XYZ, Email: user1@example.com
First Name: User2, Last Name: PQR, Email: user2@example.com
Explanation of the Code:
- In the above code, we have a JSON string
jsonString
representing an array of user objects. - We have created an
ObjectMapper
instance from the Jackson library, which helps with JSON processing. - We have used the
readValue()
method of the ObjectMapper
to convert the JSON string into an array of User
objects. We specify the type of the target array using User class
. - Then we iterate over the array of
User
objects and print the details of each user.
Similar Reads
Conversion of JSON Object Array to Java POJO In this article, we will learn how to use the widely used Jackson JSON library to map an array of JSON items to a Java POJO class instance. PrerequisitesA basic understanding of Java programming.A JSON library for Java, such as Jackson, Gson, or org.json, depending on your preference.Implementation
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 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
Java Program to Convert Byte Array to Object Converting byte array into Object and Object into a byte array process is known as deserializing and serializing. The class object which gets serialized/deserialized must implement the interface Serializable. Serializable is a marker interface that comes under package 'java.io.Serializable'.Byte Arr
2 min read
Java Program to Convert JSON String to JSON Object Gson is a Java library that can be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects whose source code we don't have. It provides the support to transfer data in between different programming languages modules. JSON S
2 min read
How to Convert a HashSet to JSON in Java? In Java, a HashSet is an implementation of the Set interface that uses a hash table to store elements. It allows fast lookups and does not allow duplicate elements. Elements in a HashSet are unordered and can be of any object type. In this article, we will see how to convert a HashSet to JSON in Jav
2 min read
Deserialize JSON Array to a Single Java Object with Jackson In Java, Deserializing an array to an object means converting the Java Array into a Single Object this is mainly done when working with object serialization. To deserialize an array to an object in Java, we typically use the Jackson library. Jackson unlocks diverse use cases, such as transforming AP
3 min read
How to Convert an ArrayList into a JSON String 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 into a JSON string in Java. Steps to convert an ArrayList into a JSON str
2 min read
How to Read and Write JSON Files in Java? JSON (JavaScript Object Notation) is simple but poweÂrful.. It helps the server and the client to share information. Applications like Java use special tools, or libraries, that reÂad JSON. In Java, some libraries make it easy to read and write JSON files. One popular library is Jackson.In this art
4 min read