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
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.7 › com › fasterxml › jackson › databind › node › ArrayNode.html
ArrayNode (jackson-databind 2.7.0 API)
Note: marked as abstract to ensure all implementation classes define it properly and not rely on definition from Object. ... Method that will produce developer-readable representation of the node; which may or may not be as valid JSON. If you want valid JSON output (or output formatted using one of other Jackson supported data formats) make sure to use ObjectMapper or ObjectWriter to serialize an instance, for example:
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
🌐
Tabnine
tabnine.com › home page › code › java › com.fasterxml.jackson.databind.node.arraynode
com.fasterxml.jackson.databind.node.ArrayNode.forEach java code examples | Tabnine
public Collection<OpenstackRouter> getRouters() { Invocation.Builder builder = getClientBuilder(neutronUrl + PATH_ROUTERS); String response = builder.accept(MediaType.APPLICATION_JSON_TYPE). header(HEADER_AUTH_TOKEN, getToken()).get(String.class); ObjectMapper mapper = new ObjectMapper(); List<OpenstackRouter> openstackRouters = Lists.newArrayList(); try { ObjectNode node = (ObjectNode) mapper.readTree(response); ArrayNode routerList = (ArrayNode) node.path(PATH_ROUTERS); OpenstackRouterCodec openstackRouterCodec = new OpenstackRouterCodec(); routerList.forEach(r -> openstackRouters .add(openstackRouterCodec.decode((ObjectNode) r, null))); } catch (IOException e) { log.warn("getRouters()", e); } log.debug("router response:" + response); openstackRouters.forEach(r -> log.debug("router ID: {}", r.id())); return openstackRouters; }
Top answer
1 of 3
89

Acquire an ObjectReader with ObjectMapper#readerFor(TypeReference) using a TypeReference describing the typed collection you want. Then use ObjectReader#readValue(JsonNode) to parse the JsonNode (presumably an ArrayNode).

For example, to get a List<String> out of a JSON array containing only JSON strings

CopyObjectMapper mapper = new ObjectMapper();
// example JsonNode
JsonNode arrayNode = mapper.createArrayNode().add("one").add("two");
// acquire reader for the right type
ObjectReader reader = mapper.readerFor(new TypeReference<List<String>>() {
});
// use it
List<String> list = reader.readValue(arrayNode);
2 of 3
13

If an Iterator is more useful...

...you can also use the elements() method of ArrayNode. Example see below.

sample.json

Copy{
    "first": [
        "Some string ...",
        "Some string ..."
    ],
    "second": [
        "Some string ..."
    ]
}

So, the List<String> is inside one of the JsonNodes.

Java

When you convert that inner node to an ArrayNode you can use the elements() method, which returns an Iterator of JsonNodes.

CopyFile file = new File("src/test/resources/sample.json");
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(file);
ArrayNode arrayNode = (ArrayNode) jsonNode.get("first");
Iterator<JsonNode> itr = arrayNode.elements();
// and to get the string from one of the elements, use for example...
itr.next().asText();

New to Jackson Object Mapper?

I like this tutorial: https://www.baeldung.com/jackson-object-mapper-tutorial

Update:

You can also use .iterator() method of ArrayNode. It is the same:

Same as calling .elements(); implemented so that convenience "for-each" loop can be used for looping over elements of JSON Array constructs.

from the javadocs of com.fasterxml.jackson.core:jackson-databind:2.11.0

🌐
Java Tips
javatips.net › api › org.codehaus.jackson.node.arraynode
Java Examples for org.codehaus.jackson.node.ArrayNode
@Override public Set<String> getImports(JavaClass klass) { final Set<String> imports = new HashSet<String>(); imports.add("org.codehaus.jackson.JsonNode"); imports.add("org.codehaus.jackson.node.ObjectNode"); if (klass.isUsedAsResult()) { imports.add("org.codehaus.jackson.node.ArrayNode"); imports.add("java.util.List"); imports.add("java.util.ArrayList"); } if (klass.isMultiType()) { for (JavaAttribute member : klass.getMembers()) { if (!member.isEnum()) { if ("boolean".equals(member.getType().getName())) { imports.add("org.codehaus.jackson.node.BooleanNode"); } if ("string".equals(member.getT
🌐
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’ll еxplorе different approaches to simplifying array operations on a JsonNodе without explicitly casting it to ArrayNode in Java. This is necessary when manipulating the data directly in our code. JsonNode is an abstract class in the Jackson library that represents a node in the JSON tree.
🌐
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 ...
Find elsewhere
🌐
Fasterxml
fasterxml.github.io › jackson-core › javadoc › 1.9 › org › codehaus › jackson › node › ArrayNode.html
ArrayNode (Jackson JSON Processor)
Method that will construct an ArrayNode and add it as a field of this ObjectNode, replacing old value, if any. ... Method that will construct an ObjectNode and add it at the end of this array node. ... Method that will construct a POJONode and add it at the end of this array node.
🌐
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
🌐
Java Tips
javatips.net › api › com.fasterxml.jackson.databind.node.arraynode
Java Examples for com.fasterxml.jackson.databind.node.ArrayNode
@Test public void testJsonPath() ... // objects. // If we have a Jackson JsonNode (an ObjectNode or an ArrayNode), we // must convert the Jackson types to Maps or Lists to use JsonPath....
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.6 › com › fasterxml › jackson › databind › node › ArrayNode.html
ArrayNode (jackson-databind 2.6.0 API)
Method that will construct an ArrayNode and add it as a field of this ObjectNode, replacing old value, if any. ... Method that will construct an ObjectNode and add it at the end of this array node. ... Method that will construct a POJONode and add it at the end of this array node.
🌐
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › 6-5 › javadoc › com › fasterxml › jackson › databind › node › ArrayNode.html
ArrayNode (The Adobe AEM Quickstart and Web Application.)
Note: class was final temporarily for Jackson 2.2. ... arrayNode, arrayNode, asText, binaryNode, binaryNode, booleanNode, missingNode, nullNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, numberNode, objectNode, pojoNode, rawValueNode, textNode · findPath, numberType, required, toPrettyString...
🌐
Baeldung
baeldung.com › home › json › jackson › jackson – unmarshall to collection/array
Jackson - Unmarshall to Collection/Array | Baeldung
April 26, 2024 - If you want to dig deeper and learn other cool things you can do with the Jackson 2 – head on over to the main Jackson tutorial. ... @Test public void givenJsonArray_whenDeserializingAsArray_thenCorrect() throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); List<MyDto> listOfDtos = Lists.newArrayList( new MyDto("a", 1, true), new MyDto("bc", 3, false)); String jsonArray = mapper.writeValueAsString(listOfDtos); // [{"stringValue":"a","intValue":1,"booleanValue":true}, // {"stringValue":"bc","intValue":3,"booleanValue":false}] MyDto[] asArray = mapper.readValue(jsonArray, MyDto[].class); assertThat(asArray[0], instanceOf(MyDto.class)); }
🌐
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › cloud-service › javadoc › com › fasterxml › jackson › databind › node › ArrayNode.html
ArrayNode (The Adobe Experience Manager SDK 2022.11.9850.20221116T162329Z-220900)
Method is functionally equivalent to path(index).required() and can be used to check that this node is an ArrayNode (that is, represents JSON Array value) and has value for specified index (but note that value may be explicit JSON null value).
🌐
Java Code Geeks
javacodegeeks.com › home › enterprise java
Simplified Json Array Operations with JsonNode in Jackson
May 6, 2024 - Let’s dive into these methods step by step to enhance your JSON manipulation skills in Java. Jackson is a popular Java library used for JSON processing. JsonNode is a fundamental abstraction representing a node in the JSON tree structure, capable of representing various JSON types such as objects, arrays, strings, numbers, and more. 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.
🌐
GitHub
github.com › nasa › astrobee_gds › blob › master › org.codehaus.jackson.json › jackson-src-1.8.5 › src › mapper › java › org › codehaus › jackson › node › ArrayNode.java
astrobee_gds/org.codehaus.jackson.json/jackson-src-1.8.5/src/mapper/java/org/codehaus/jackson/node/ArrayNode.java at master · nasa/astrobee_gds
import org.codehaus.jackson.map.TypeSerializer; · /** * Node class that represents Arrays mapped from Json content. */ public final class ArrayNode · extends ContainerNode · { protected ArrayList<JsonNode> _children; · public ArrayNode(JsonNodeFactory nc) { super(nc); } ·
Author   nasa
🌐
Mkyong
mkyong.com › home › java › how to parse json array with jackson
How to parse JSON Array with Jackson - Mkyong.com
April 23, 2024 - The technique is the same with the above example 4: first converts the JSON string to Map<String, List<Person>> and manually get the List<Person> later. { "Person" : [ { "name" : "mkyong", "age" : 42 }, { "name" : "ah pig", "age" : 20 } ] } ... package com.mkyong.json.jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.mkyong.json.model.Person; import java.util.List; import java.util.Map; public class JsonArrayToObjectExample4 { public static void main(String[] a