Properly escape xml values and add JSON output

I've noticed a problem with xml output where it isn't encoding special characters (like &), which caused parsing to fail. This should properly encode the values.

This will also add JSON as an output format (for use in other programs which wish to have another output option)