Clean up error handling in encodeJson