code: def round_floats_for_json(obj, ndigits=2, key_ndigits=None):
      """
      Tries to round all floats in obj in order to reduce json size.
      ndigits is the default number of digits to round to,
      key_ndigits allows you to override this for specific dictionary keys,
      though there is no concept of nested keys.
      It converts numpy arrays and iterables to lists,
      so it should only be used when serializing to json
      """
      if key_ndigits is None:
          key_ndigits = {}
  
      if isinstance(obj, np.floating):
          obj = float(obj)
      elif isinstance(obj, np.ndarray):
          obj = obj.tolist()
  
      if isinstance(obj, float):
          obj = round(obj, ndigits)
      elif isinstance(obj, dict):
          new_obj = {}
          for k, v in obj.items():
              this_ndigits = key_ndigits.get(k, ndigits)
              new_obj[k] = round_floats_for_json(
                  v, this_ndigits, key_ndigits
              )
          return new_obj
      elif isinstance(obj, str):
          return obj
      else:
          try:
              return [
                  round_floats_for_json(x, ndigits, key_ndigits)
                  for x in obj
              ]
          except TypeError:
              pass
  
      return obj
  
file_path: gluon-cv/gluoncv/torch/data/gluoncv_motion_dataset/utils/serialization_utils.py
imports: import json
  import pickle
  import pathlib
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: round_floats_for_json(obj, ndigits, key_ndigits) and returns: obj, new_obj, obj, unknown