Convert JSON to Map using Jackson

In this post we will provide an example of how to convert JSON to a Map using Jackson.

Setup:

You will need to add the following dependancy to your project (to include the Jackson library)

Convert JSON to Map:

The following example shows how to convert JSON to a Map using the ObjectMapper class. The ObjectMapper class has a very useful method readValue() which takes a JSON string and your target Class.

Running the above code produces the following output:

The ObjectMapper class also works for JSON objects which have a nested structure as shown in the example below.

Running the above example produces the following output

In conclusion, I hope you found this post useful and it has showed you how to use the Jackson library in a new way.

Similar posts:

  1. Java map to JSON using jackson
  2. JSON array to List using Jackson
  3. Convert java object to JSON using Jackson
  4. Parse JSON using Jackson

References:

  1. Jackson Documentation

 

Leave a Reply