A good pretty-printer for Google Gson

I decided to do something about the one thing I wasn’t happy about in Google Gson, the lack of good pretty-printing.

I created a class called GsonPrettyPrinter which outputs nice readable JSON in a reasonably intelligent way, you can grab the source code here.

Note, in particular:

  • Requires at least Gson 1.4 (the current version at the time of writing)
  • It will try to represent JSON objects on arrays on a single line if it can
  • It sorts JSON objects by their keys
  • The code is released under the Lesser Gnu Public License.

One thought on “A good pretty-printer for Google Gson

  1. Pingback: Which is the best Java JSON library? | Hypergraphia Indulged

Leave a Reply

Your email address will not be published. Required fields are marked *