trap errors when serializing/deserializing JSON