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.