Use to_json to catch JSON encode errors