Handle invalid input more carefully.

In particular, catch the relevant exceptions thrown by the json parser
and schema.

This also adds a handful of related tests.