Yes, the Jackson manual parser design is quite different from other libraries. In particular, you will notice that JsonNode has most of the functions that you would typically associate with array nodes from other APIs. As such, you do not need to cast to an ArrayNode to use. Here's an example:

JSON:

{
    "objects" : ["One", "Two", "Three"]
}

Code:

final String json = "{\"objects\" : [\"One\", \"Two\", \"Three\"]}";

final JsonNode arrNode = new ObjectMapper().readTree(json).get("objects");
if (arrNode.isArray()) {
    for (final JsonNode objNode : arrNode) {
        System.out.println(objNode);
    }
}

Output:

"One"
"Two"
"Three"

Note the use of isArray to verify that the node is actually an array before iterating. The check is not necessary if you are absolutely confident in your data structure, but it's available should you need it (and this is no different from most other JSON libraries).

Answer from Perception on Stack Overflow
🌐
Javadoc.io
javadoc.io › doc › com.fasterxml.jackson.core › jackson-databind › latest › com › fasterxml › jackson › databind › node › ArrayNode.html
ArrayNode - jackson-databind 2.21.1 javadoc
Bookmarks · Latest version of com.fasterxml.jackson.core:jackson-databind · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind · Current version 2.21.1 · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.21.1 · package-list path (used for javadoc generation ...
🌐
Medium
medium.com › @lakshmanaselvan252 › explain-about-the-jsonnode-and-arraynode-in-spring-boot-17f81c3de915
Explain About The JsonNode And ArrayNode In Spring Boot | by Lakshmana Selvan V | Medium
August 21, 2024 - Parsing JSON: The objectMapper... the entire JSON structure as a tree. ... ArrayNode is a subclass of JsonNode specifically designed to represent JSON arrays....
🌐
Java Code Geeks
javacodegeeks.com › home › enterprise java
Simplified Json Array Operations with JsonNode in Jackson
May 6, 2024 - When working with JSON arrays ([]), the ArrayNode class in Jackson is especially useful for handling Simplified Array Operations on JsonNode in Jackson, enabling efficient manipulation and traversal of JSON arrays within Java applications.
🌐
DEV Community
dev.to › abharangupta › dive-into-jackson-for-json-in-java-understanding-jsonnode-arraynode-and-objectmapper-30g4
Dive into Jackson for JSON in Java: Understanding JsonNode, ArrayNode, and ObjectMapper - DEV Community
October 22, 2024 - ArrayNode: How to handle JSON arrays. ObjectMapper: How to serialize and deserialize Java objects to and from JSON. I hope this guide makes Jackson a little less intimidating and a lot more fun to use!
🌐
Baeldung
baeldung.com › home › json › jackson › simplified array operations on jsonnode without typecasting in jackson
Simplified Array Operations on JsonNode Without Typecasting in Jackson | Baeldung
June 27, 2025 - In this tutorial, we explored various approaches to simplifying array operations on JsonNode without explicitly typecasting it to ArrayNode in Jackson.
Find elsewhere
🌐
Attacomsian
attacomsian.com › blog › jackson-create-json-array
How to create a JSON array using Jackson
October 14, 2022 - try { // create `ObjectMapper` instance ObjectMapper mapper = new ObjectMapper(); // create three JSON objects ObjectNode user1 = mapper.createObjectNode(); user1.put("id", 1); user1.put("name", "John Doe"); ObjectNode user2 = mapper.createObjectNode(); user2.put("id", 2); user2.put("name", "Tom Doe"); ObjectNode user3 = mapper.createObjectNode(); user3.put("id", 3); user3.put("name", "Emma Doe"); // create `ArrayNode` object ArrayNode arrayNode = mapper.createArrayNode(); // add JSON users to array arrayNode.addAll(Arrays.asList(user1, user2, user3)); // convert `ArrayNode` to pretty-print JS
Top answer
1 of 2
5

Assuming that a row is one of the entries in a ArrayNode the following simple approach may be useful. It uses the JsonNode abstraction instead of a series of nested Map objects which I personally prefer since JsonNode provides a series of utility methods that are helpful when dealing with this kind of data (data where the structure is possibly unknown or very dynamic so that it can't be easily transformed to a POJO).

The testcase below illustrates how to find the number of rows and how to print the values. To get hold of the values the method JsonNode.elements() is used and the number of rows is simply a call to the size()-method.

public class ArrayNodeTest {
    @Test
    public void verifySizeAndPrintRows() throws IOException {
        final String jsonStr =
                "[{\"key11\":\"value11\",\"key12\":\"value12\"},\n" +
                        "{\"key21\":\"value21\",\"key22\":\"value22\"},\n" +
                        "{\"keyn1\":\"valuen1\",\"keyn2\":\"valuen2\"}]";

        final ObjectMapper mapper = new ObjectMapper();
        final JsonNode jsonNode = mapper.readTree(jsonStr);

        // Verify size
        Assert.assertEquals(3, jsonNode.size());

        // And print rows
        for (final JsonNode row : jsonNode) {
            final Iterable<JsonNode> iterable = () -> row.elements();
            iterable.forEach(elem -> System.out.println(elem.asText()));
        }
    }
}
2 of 2
0

to identify the number of rows

What's a "row"? Is a key/value pair a row? Is an element of the JSON array (no matter how many key/value pairs it contains) a row?

print only the values on the screen

Jackson has nothing to do with printing anything on any screens. Jackson can be used to populate a Java data structure from the input JSON, and the populated Java data structure can then be used however you want.

Given the JSON structure in the original question, a simple solution would be to bind to a list (or array) of maps, and then just iterate through the list of maps, accessing all of the values. Following is such an example.

import java.io.File;
import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper;

public class JacksonFoo
{
  public static void main(String[] args) throws Exception
  {
    ObjectMapper mapper = new ObjectMapper();
    Map<String, String>[] maps = mapper.readValue(new File("input.json"), Map[].class);
    for (Map<String, String> map : maps)
    {
      for (Map.Entry<String, String> entry : map.entrySet())
      {
        System.out.println(entry.getValue());
      }
    }
  }
}

Output:

value11
value12
value21
value22
valuen1
valuen2
🌐
mysql
dev.cs.ovgu.de › java › jackson › api › index.html
ArrayNode (Jackson JSON parser 0.9.1)
Jackson JSON parser 0.9.1 · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link toNon-frame version
🌐
Camunda
forum.camunda.io › camunda 7 topics › discussion & questions
Jackson - ClassCastException ArrayNode to ArrayNode - Discussion & Questions - Camunda Forum
November 10, 2016 - I think this may be a known issue due to library differences within Spin. I’m seeing this odd cast exception: Caused by: java.lang.ClassCastException: com.fasterxml.jackson.databind.node.ArrayNode cannot be cast to com.fasterxml.jackson.databind.node.ArrayNode Causing the error if(processVariableValue.getClass().getSimpleName().equalsIgnoreCase("JacksonJsonNode")) { if( ((Spin)processVariableValue).unwrap().getClass().getSimpleName().equalsIgnoreCase("ArrayNode")) { ...
🌐
Medium
medium.com › @tejeswar_79802 › dive-into-jackson-for-json-in-java-understanding-jsonnode-arraynode-and-objectmapper-f302329d9919
Dive into Jackson for JSON in Java: Understanding JsonNode, ArrayNode, and ObjectMapper | by TEJESWAR REDDY | Oct, 2024 | Medium
November 14, 2024 - Here's an example demonstrating the use of ObjectNode and ArrayNode:javaimport com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.node.ArrayNode;import com.fasterxml.jackson.databind.node.ObjectNode;public class ObjectNodeArrayNodeExample {public static void main(String args) throws Exception {// Create an ObjectMapper instanceObjectMapper objectMapper = new ObjectMapper();// Create an ObjectNode for the root elementObjectNode rootNode = objectMapper.createObjectNode();// Create an ArrayNode for the "friends" fieldAr
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 3882
Error in creating nested `ArrayNode`s with `JsonNode. ...
April 15, 2023 - @Test public static void test_nestedArray() { ObjectMapper mapper = new ObjectMapper(); String json = "{}"; try { JsonNode jsonObject = mapper.readTree(json); ArrayNode aN = jsonObject.withArray("/key1/array1/0/element1", JsonNode.OverwriteMode.ALL, true); aN.add("v1"); aN.add("v2"); aN.add("v3"); } catch (Exception e) { e.printStackTrace(); } } Executing this method is throwing: java.lang.UnsupportedOperationException: Cannot replace context node (of type `com.fasterxml.jackson.databind.node.ObjectNode`) using `withArray()` with JSON Pointer '/key1/array1/0/element1' at com.fasterxml.jackson.
Author   SaiKrishna369
🌐
Tabnine
tabnine.com › home page › code › java › com.fasterxml.jackson.databind.node.arraynode
com.fasterxml.jackson.databind.node.ArrayNode.add java code examples | Tabnine
public String toJSON() { ArrayNode array = JACKSON_MAPPER.createArrayNode(); for (RequestAttempt attempt : this) { array.add(attempt.toJsonNode()); } try { return JACKSON_MAPPER.writeValueAsString(array); } catch (JsonProcessingException e) { throw new RuntimeException("Error serializing RequestAttempts!", e); } }
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-jsonnode.html
Jackson JsonNode
The Jackson JsonNode class is the Jackson tree object model for JSON. Jackson can read JSON into an object graph (tree) of JsonNode objects. Jackson can also write a JsonNode tree to JSON.
🌐
The Hindu
thehindu.com › news › cities › bangalore › an-array-of-pattada-gombes-light-up-this-home › article68732852.ece
An array of Pattada Gombes light up this home - The Hindu
October 10, 2024 - Dasara celebrations in Karnataka include Gombe Habba, featuring a display of dolls and figurines to mark Navaratri nights.