mabuzer mabuzer - 1 year ago 126
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 Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download