code: def dump(obj, fname, compressed=False):
      """Dump a JSON-serializable objects into a file
  
      Parameters
      ----------
      obj : object
        Structure to serialize.
      fname : str
        Name of the file to dump into.
      compressed : bool
        Flag whether to use LZMA compression for file content.
      """
  
      _open = LZMAFile if compressed else io.open
  
      indir = dirname(fname)
      if not exists(indir):
          makedirs(indir)
      if lexists(fname):
          os.unlink(fname)
      with _open(fname, "wb") as f:
          return dump2fileobj(
              obj,
              f,
              **(
                  compressed_json_dump_kwargs
                  if compressed
                  else json_dump_kwargs
              ),
          )
  
file_path: datalad/datalad/support/json_py.py
imports: import io
  import codecs
  from os.path import dirname, exists, lexists
  from os import makedirs
  import os
  import os.path
  import json
  from datalad.support.exceptions import CapturedException
  from ..log import lgr
label_desc: Use image node_id 1 for calling a global function with example usage: dump(obj, fname, compressed) and returns: dump2fileobj