mabuzer mabuzer - 1 month ago 18
JSON Question

Pretty-Print JSON in Java

I'm using and I need to pretty-print JSON data (make it more human readable).

I haven't been able to find this functionality within that library.
How is this commonly achieved?

Answer

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);
Comments