Pretty print JSON in Java (Jackson)

The Pretty print JSON in Java tutorial shows you how to use Jackson pretty print for JSON Object and String in the console.

Other interesting posts you may like

Pretty Print JSON Object
Example to convert Object and jackson pretty print its output in JSON format.

And the json output is in compact mode.

To enable jackson pretty print, use writerWithDefaultPrettyPrinter.

And here is pretty output

Pretty Print JSON String

Now we can try to use writerWithDefaultPrettyPrinter again .

Here is output:

And not what we want, json string is still in compact mode. We solve it by using a bit tricky that bind the JSON string to Object class before pretty print it.

And here is pretty output

That’s it. This Pretty print JSON in Java tutorial is quite simple by using Jackson framework. You can get JSON pretty print with good tool online Pretty Print JSON

Leave a Comment

*

Please share it if you found this useful
Hide Buttons