code: def dump2stream(obj, fname, compressed=False):
      _open = LZMAFile if compressed else open
  
      indir = dirname(fname)
  
      if op.lexists(fname):
          os.remove(fname)
      elif indir and not exists(indir):
          makedirs(indir)
      with _open(fname, mode="wb") as f:
          jwriter = codecs.getwriter("utf-8")(f)
          for o in obj:
              json.dump(o, jwriter, **compressed_json_dump_kwargs)
              f.write(b"\n")
  
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 4 for calling a global function with example usage: dump2stream(obj, fname, compressed) without return types