Reputation: 860
Simply put, how do I retrieve {"value1":123"} using Jackson in a non-chaining way?
{
"aaa": [
{
"value1": "123"
}
],
"bbb": [
{
"value2": "456"
}
]
}
I tried using:
jsonNode.at("/aaa[Array][0])
but i get missing node in response.
Any help would be good.
Upvotes: 5
Views: 6336
Reputation: 96
Using node.path("aaa").get(0) is what retrieved the first item from array. Any other ideas like node.path("aaa[0]") or node.path("aaa/0") do not work.
Upvotes: 1
Reputation: 3677
The correct json path expression would be "/aaa/0/value1"
Use:
jsonNode.at("/aaa/0/value1")
Upvotes: 9
Reputation: 573
use this below code :
JsonNode node = mapper.readTree(json);
System.out.println(node.path("aaa").get(0)); // {"value1":"123"}
node.path("aaa").get(0).get("value1") // 123.
Upvotes: 1