mabuzer mabuzer - 5 months ago 70
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?


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