code: def _json_serial_task_result(result: Optional[TaskResult]):
      if result is None:
          return {}
      res_json = {
          "task_id": result.task_id,
          "session_id": result.session_id,
          "stage_id": result.stage_id,
          "start_time": result.start_time,
          "end_time": result.end_time,
          "progress": result.progress,
          "status": result.status.value,
          "profiling": result.profiling,
      }
      if result.error is not None:
          res_json["error"] = base64.b64encode(
              serialize_serializable(result.error)
          ).decode()
          res_json["traceback"] = base64.b64encode(
              serialize_serializable(result.traceback)
          ).decode()
          res_json["traceback_code"] = dump_traceback_code(
              result.traceback
          )
      return res_json
  
file_path: mars/mars/services/task/api/web.py
imports: import asyncio
  import base64
  import json
  from typing import Callable, List, Optional, Union
  from ....core import TileableGraph, Tileable
  from ....lib.tbcode import load_traceback_code, dump_traceback_code
  from ....utils import serialize_serializable, deserialize_serializable
  from ...web import web_api, MarsServiceWebAPIHandler, MarsWebAPIClientMixin
  from ..core import TaskResult, TaskStatus
  from .core import AbstractTaskAPI
label_desc: Use image node_id 1 for calling a global function with example usage: _json_serial_task_result(result) and returns: res_json, dict