code: def dump_metadata_json(
      reader: GGUFReader, args: argparse.Namespace
  ) -> None:
      import json
  
      host_endian, file_endian = get_file_host_endian(reader)
      metadata: dict[str, Any] = {}
      tensors: dict[str, Any] = {}
      result = {
          "filename": args.model,
          "endian": file_endian,
          "metadata": metadata,
          "tensors": tensors,
      }
      for idx, field in enumerate(reader.fields.values()):
          curr: dict[str, Any] = {
              "index": idx,
              "type": field.types[0].name if field.types else "UNKNOWN",
              "offset": field.offset,
          }
          metadata[field.name] = curr
          if field.types[:1] == [GGUFValueType.ARRAY]:
              curr["array_types"] = [t.name for t in field.types][1:]
              if not args.json_array:
                  continue
              itype = field.types[-1]
              if itype == GGUFValueType.STRING:
                  curr["value"] = [
                      str(bytes(field.parts[idx]), encoding="utf-8")
                      for idx in field.data
                  ]
              else:
                  curr["value"] = [
                      pv
                      for idx in field.data
                      for pv in field.parts[idx].tolist()
                  ]
          elif field.types[0] == GGUFValueType.STRING:
              curr["value"] = str(
                  bytes(field.parts[-1]), encoding="utf-8"
              )
          else:
              curr["value"] = field.parts[-1].tolist()[0]
      if not args.no_tensors:
          for idx, tensor in enumerate(reader.tensors):
              tensors[tensor.name] = {
                  "index": idx,
                  "shape": tensor.shape.tolist(),
                  "type": tensor.tensor_type.name,
                  "offset": tensor.field.offset,
              }
      json.dump(result, sys.stdout)
  
file_path: llama.cpp/gguf-py/scripts/gguf-dump.py
imports: from __future__ import annotations
  import argparse
  import os
  import sys
  from pathlib import Path
  from typing import Any
  import numpy
  from gguf import GGUFReader, GGUFValueType
label_desc: Use image node_id 3 for calling a global function with example usage: dump_metadata_json(reader, args) without return types