<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_dict(obj):
 """Generate a JSON serialization for the run state object. Returns ------- Json-like object Json serialization of model run state object """

        # Have text description of state in Json object (for readability)
        json_obj = {'type' : repr(obj)}
        # Add state-specific elementsTYPE_MODEL_RUN
        if obj.is_failed:
            json_obj['errors'] = obj.errors
        elif obj.is_success:
            json_obj['modelOutput'] = obj.model_output
        return json_obj