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. Pretty Print JSON Object Example to convert Object and jackson pretty print its output in JSON format.
1 2 3 4 5 6 7 8 9 |
Student student = new Student(); //set student data student.setName("David"); student.setAge("35"); student.setCourses(new String[]{"Math","Foreign Language","Animal Biology"}); //print json format ObjectMapper mapper = new ObjectMapper(); System.out.println(mapper.writeValueAsString(student)); |
And the json output is in compact mode.
1 |
{"name":"David","age":35,"courses":["Math","Foreign Language","Animal Biology"]} |
To enable jackson pretty print, … Read morePretty print JSON in Java (Jackson)