code: def history_dict_to_json(
      run: Optional["LocalRun"],
      payload: dict,
      step: Optional[int] = None,
      ignore_copy_err: Optional[bool] = None,
  ) -> dict:
      # Converts a History row dict's elements so they're friendly for JSON serialization.
  
      if step is None:
          # We should be at the top level of the History row; assume this key is set.
          step = payload["_step"]
  
      # We use list here because we were still seeing cases of RuntimeError dict changed size
      for key in list(payload):
          val = payload[key]
          if isinstance(val, dict):
              payload[key] = history_dict_to_json(
                  run, val, step=step, ignore_copy_err=ignore_copy_err
              )
          else:
              payload[key] = val_to_json(
                  run,
                  key,
                  val,
                  namespace=step,
                  ignore_copy_err=ignore_copy_err,
              )
  
      return payload
  
file_path: wandb/wandb/sdk/data_types/utils.py
imports: import logging
  import os
  import re
  from typing import TYPE_CHECKING, Optional, Sequence, Union, cast
  import wandb
  from wandb import util
  from .base_types.media import BatchableMedia, Media
  from .base_types.wb_value import WBValue
  from .image import _server_accepts_image_filenames
  from .plotly import Plotly
label_desc: Use image node_id 1 for calling a global function with example usage: history_dict_to_json(run, payload, step, ignore_copy_err) and returns: payload