code: def _write_missing_references_json(records, json_path):
      """
      Convert ignored references to a format which we can write as JSON
  
      Convert from ``{(domain_type, target): locations}`` to
      ``{domain_type: {target: locations}}`` since JSON can't serialize tuples.
      """
      # Sorting records and keys avoids needlessly big diffs when
      # missing_references.json is regenerated.
      transformed_records = defaultdict(dict)
      for (domain_type, target), paths in records.items():
          transformed_records[domain_type][target] = sorted(paths)
      with json_path.open("w") as stream:
          json.dump(
              transformed_records, stream, sort_keys=True, indent=2
          )
  
imports: from collections import defaultdict
  import json
  import logging
  from pathlib import Path
  from docutils.utils import get_source_line
  from docutils import nodes
  from sphinx.util import logging
  import matplotlib
label_desc: Use image node_id 7 for calling a global function with example usage: _write_missing_references_json(records, json_path) without return types