code: def write_json(
      fig, file, validate=True, pretty=False, remove_uids=True
  ):
      """
      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. 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
  
      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
      )
  
      # Check if file is a string
      # -------------------------
      file_is_str = isinstance(file, string_types)
  
      # Open file
      # ---------
      if file_is_str:
          with open(file, "w") as f:
              f.write(json_str)
      else:
          file.write(json_str)
  
imports: from __future__ import absolute_import
  from six import string_types
  import json
  from plotly.io._utils import validate_coerce_fig_to_dict, validate_coerce_output_type
label_desc: Use image node_id 2 for calling a global function with example usage: write_json(fig, file, validate, pretty, remove_uids) without return types