I want to format a string containing JSON data using Java. Does anybody know an open source library for that.
With Jackson 2.6.1
String beautify(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Object obj = mapper.readValue(json, Object.class);
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
}
pom.xml:
com.fasterxml.jackson.core
jackson-core
2.6.1
com.fasterxml.jackson.core
jackson-databind
2.6.1
Convert JSON String to Pretty Print JSON output using Jackson