Add a new switch to output JSON data when run in debug mode

This will enable using the output in external scripts. For example, the
JSON output can be fed to another script which can then decode the data
to a machine readable data structure.

Change-Id: I5183b73c1b5bdf28ea171d28c8ca1f173f1a09bf