
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Search Value Inside a JSON File Using Jackson in Java
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.
Syntax
public JsonNode get(String fieldName)
Example
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")); } } }
Output
NAME: "Raja Ramesh"
Advertisements