code: def get_jsonhooks_from_config(cfg):
      """Parse out hook definitions given a ConfigManager instance
  
      Returns
      -------
      dict
        where keys are hook names/labels, and each value is a dict with
        three keys: 'cmd' contains the name of the to-be-executed DataLad
        command; 'args' has a JSON-encoded string with a dict of keyword
        arguments for the command (format()-language based placeholders
        can be present); 'match' holds a JSON-encoded string representing
        a dict with key/value pairs that need to match a result in order
        for a hook to be triggered.
      """
      hooks = {}
      for h in cfg.keys():
          if not (
              h.startswith("datalad.result-hook.")
              and h.endswith(".match-json")
          ):
              continue
          hook_basevar = h[:-11]
          hook_name = hook_basevar[20:]
          # do not use a normal `get()` here, because it reads the committed dataset
          # config too. That means a datalad update can silently bring in new
          # procedure definitions from the outside, and in some sense enable
          # remote code execution by a 3rd-party
          call = cfg.get_from_source(
              "local", "{}.call-json".format(hook_basevar), None
          )
          if not call:
              lgr.warning(
                  "Incomplete result hook configuration %s in %s",
                  hook_basevar,
                  cfg,
              )
              continue
          # split command from any args
          call = call.split(maxsplit=1)
          # get the match specification in JSON format
          try:
              match = json.loads(cfg.get(h))
          except Exception as e:
              ce = CapturedException(e)
              lgr.warning(
                  "Invalid match specification in %s: %s [%s], "
                  "hook will be skipped",
                  h,
                  cfg.get(h),
                  ce,
              )
              continue
  
          hooks[hook_name] = dict(
              cmd=call[0],
              # support no-arg calls too
              args=call[1] if len(call) > 1 else "{{}}",
              match=match,
          )
      return hooks
  
imports: import logging
  import json
  from datalad.support.exceptions import CapturedException
label_desc: Use image node_id 1 for calling a global function with example usage: get_jsonhooks_from_config(cfg) and returns: hooks