Skip to content

Instantly share code, notes, and snippets.

@ashwinrs
Created February 1, 2018 22:03
Show Gist options
  • Save ashwinrs/84627536f2a74dc900228e8da4ce7800 to your computer and use it in GitHub Desktop.
Save ashwinrs/84627536f2a74dc900228e8da4ce7800 to your computer and use it in GitHub Desktop.
Pretty Print a JSON in Java
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(GSON.toJson(<Object>));
String prettyJsonString = gson.toJson(je);
System.out.println(prettyJsonString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment