How to search a value inside a JSON file using Jackson in Java?

JavaJSONObject Oriented ProgrammingProgramming

The com.fasterxml.jackson.databind.node.ObjectNode class can be used to map the JSON object structure in Json content. We can search for a particular value inside the JSON file using the get() method of ObjectNode class, this method used for accessing the value of a specified field of an object node.


public JsonNode get(String fieldName)


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class ObjectNodeTest {
   public static void main(String args[]) throws Exception {
      String jsonString = "{\"Id\":101, \"name\":\"Raja Ramesh\", \"address\":\"Madhapur\"}";
      ObjectMapper mapper = new ObjectMapper();
      ObjectNode node = mapper.readValue(jsonString, ObjectNode.class);
      if(node.has("name")) {
         System.out.println("NAME: " + node.get("name"));


NAME: "Raja Ramesh"
Updated on 09-Jul-2020 07:52:12