code: def write_json(
      fig,
      file,
      validate=True,
      pretty=False,
      remove_uids=True,
      engine=None,
  ):
      """
      Convert a figure to JSON and write it to a file or writeable
      object
  
      Parameters
      ----------
      fig:
          Figure object or dict representing a figure
  
      file: str or writeable
          A string representing a local file path or a writeable object
          (e.g. a pathlib.Path object or an open file descriptor)
  
      pretty: bool (default False)
          True if JSON representation should be pretty-printed, False if
          representation should be as compact as possible.
  
      remove_uids: bool (default True)
          True if trace UIDs should be omitted from the JSON representation
  
      engine: str (default None)
          The JSON encoding engine to use. One of:
            - "json" for an engine based on the built-in Python json module
            - "orjson" for a faster engine that requires the orjson package
            - "auto" for the "orjson" engine if available, otherwise "json"
          If not specified, the default engine is set to the current value of
          plotly.io.json.config.default_engine.
      Returns
      -------
      None
      """
  
      # Get JSON string
      # ---------------
      # Pass through validate argument and let to_json handle validation logic
      json_str = to_json(
          fig,
          validate=validate,
          pretty=pretty,
          remove_uids=remove_uids,
          engine=engine,
      )
  
      # Try to cast `file` as a pathlib object `path`.
      # ----------------------------------------------
      if isinstance(file, str):
          # Use the standard Path constructor to make a pathlib object.
          path = Path(file)
      elif isinstance(file, Path):
          # `file` is already a Path object.
          path = file
      else:
          # We could not make a Path object out of file. Either `file` is an open file
          # descriptor with a `write()` method or it's an invalid object.
          path = None
  
      # Open file
      # ---------
      if path is None:
          # We previously failed to make sense of `file` as a pathlib object.
          # Attempt to write to `file` as an open file descriptor.
          try:
              file.write(json_str)
              return
          except AttributeError:
              pass
          raise ValueError(
              """
  The 'file' argument '{file}' is not a string, pathlib.Path object, or file descriptor.
  """.format(
                  file=file
              )
          )
      else:
          # We previously succeeded in interpreting `file` as a pathlib object.
          # Now we can use `write_bytes()`.
          path.write_text(json_str)
  
imports: import json
  import decimal
  import datetime
  import warnings
  from pathlib import Path
  from plotly.io._utils import validate_coerce_fig_to_dict, validate_coerce_output_type
  from _plotly_utils.optional_imports import get_module
  from _plotly_utils.basevalidators import ImageUriValidator
label_desc: Use image node_id 5 for calling a global function with example usage: write_json(fig, file, validate, pretty, remove_uids, engine) without return types