I moved most of the printing code from HistoryViewer into a new class, so I could create an interface to be able to implement other output formats. A lot of the patch is moving that existing code. Otherwise, the patch adds the new JobHistoryViewerJSONPrinter class, which prints mostly the same information as the JobHistoryViewerHumanPrinter. It omits the Analysis section, as that's not really necessary for this use case, and changes a few other things to be more machine-friendly (e.g. using counter names instead of counter display names and other misc formatting). I didn't change any of the formatting of the existing human readable output for backwards compatibility.
I also added the ability to specify an output file for the results, which works for either format and cleaned up the CLI parsing for this subcommand.
The command now looks like this:
mapred job -history [all] <jobHistoryFile> [-outfile <file>] [-format <human|json>]]
It defaults to the human format and stdout.