Here you can find the source of formatJSON(String jsonData)
public static String formatJSON(String jsonData) throws JsonProcessingException, IOException
//package com.java2s; //License from project: Apache License import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; public class Main { private static ObjectMapper mapper = new ObjectMapper(); public static String formatJSON(String jsonData) throws JsonProcessingException, IOException { Object obj = mapper.readValue(jsonData, Object.class); return toJSON(obj); }// w w w . j a va2 s.c o m public static String toJSON(Object o) throws JsonProcessingException { return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(o); } }