Fix exception hierarchy and solution for issue #2

Sorry I should have done 5ba83dc as two separate commits. I just moved the JSON building into its own class because it makes the exception handling easier and the code a bit cleaner.