Pretty-Print JSON in Java

Google’s GSON can do this in a nice way: Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(uglyJsonString); String prettyJsonString = gson.toJson(je); or since it is now recommended to use the static parse method from JsonParser you can also use this instead: Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonElement je = … Read more