Add error handling in json deserializer

Targets #636.