Convert a List to JSON array using Jackson

In this post we will show how to convert a List to JSON array using Jackson.

Setup:

In this example you will need to add the following dependancy

Convert a List to JSON array:

The example below shows how to convert a java list to a JSON array using the Jackson parser.

As you can see from the above example, the ObjectMapper class has a very useful method which will accept a List object and return a JSON array as a String.

Output:

Running the above code produces the following output

In conclusion I hope the you found this post useful

Similar posts:

  1. How to parse JSON using Jackson
  2. How to parse a JSON string to a Java object
  3. How to convert a Java object to JSON using Jackson
  4. Json array to List using GSON

References:

  1. Jackson documentation

Leave a Reply