-3
{  
   "first":"element",
   "second":"Integral",
   "isThird":false,
   "fourth":{  
      "ONE":[  
         {  
            "100":"Cars"
         },
         {  
            "200":"Truck"
         }
      ],
      "TWO":[  
         {  
            "6":"Vintage"
         },
         {  
            "4":"Sports"
         }
      ]
   }
}

I have a json where I am using Jackson to break in Java Object form. I want to know how I can break this json into simplest form using Jackson.

This is my Jackson Dependency used

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.6.0</version>
</dependency>
Tatkal
  • 568
  • 4
  • 9
  • 29

2 Answers2

0

First you have to prepare a matching class structure to your JSON. If that is done instantiate an ObjectMapper in your code and grab the Objects from them.

ObjectMapper mapper = new ObjectMapper();
YourType unmarshalledJson = mapper.readValue(jsonString,YourType.class);
OkieOth
  • 3,604
  • 1
  • 19
  • 29
0

Use Gson Api.

JsonParser parser=new JsonParser();
JsonObject jsonObj=(JsonObject) parser.parse("Your Json String");

String first=jsonObj.get("first");                     // first and second are String in json
String second=jsonObj.get("second");

JsonObject fourth=jsonObj.getAsJsonObject("fourth");  // because fourth is Object in json

// And so on......
Tarun
  • 986
  • 6
  • 19