Here is an example json
{
"key1": {
"key2": {
"key3": "value3"
}
}
}
I want to get the value of key3, which is "value3"
The method findValue of JsonNode class should serve the purpose here.
so I tried the following:
final ObjectMapper jsonMapper = new ObjectMapper();
String jsonRoot = "{\"key1\":\n" + " {\"key2\":\n" + " {\"key3\":\"value3\"}\n" + " }\n" + "}";
JsonNode node = jsonMapper.convertValue(jsonRoot,JsonNode.class);
JsonNode found = node.findValue("key3");
System.out.println(found.asText());
System.out.println(found.isObject());
However, I see "found" is null. I am unable to figure out why this failing. I also tried node.findValue("key2"). I still get null.
Thanks
There is difference in between these 2 methods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With