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
Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s
10 min read
Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per
15+ min read
Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it,
13 min read
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me
15+ min read
Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an
13 min read
Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac
15+ min read
Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt
10 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read