code: def convert_to_json(
      metadata_buffer,
      custom_metadata_schema: Optional[Dict[str, str]] = None,
  ) -> str:
      """Converts the metadata into a json string.
  
      Args:
        metadata_buffer: valid metadata buffer in bytes.
        custom_metadata_schema: A dict of custom metadata schema, in which key is
          custom metadata name [1], value is the filepath that defines custom
          metadata schema. For instance, custom_metadata_schema =
          {"SEGMENTER_METADATA": "metadata/vision_tasks_metadata_schema.fbs"}. [1]:
            https://github.com/google/mediapipe/blob/46b5c4012d2ef76c9d92bb0d88a6b107aee83814/mediapipe/tasks/metadata/metadata_schema.fbs#L612
  
      Returns:
        Metadata in JSON format.
  
      Raises:
        ValueError: error occurred when parsing the metadata schema file.
      """
      opt = _pywrap_flatbuffers.IDLOptions()
      opt.strict_json = True
      parser = _pywrap_flatbuffers.Parser(opt)
      with _open_file(_FLATC_TFLITE_METADATA_SCHEMA_FILE) as f:
          metadata_schema_content = f.read()
      if not parser.parse(metadata_schema_content):
          raise ValueError(
              "Cannot parse metadata schema. Reason: " + parser.error
          )
      # Json content which may contain binary custom metadata.
      raw_json_content = _pywrap_flatbuffers.generate_text(
          parser, metadata_buffer
      )
      if not custom_metadata_schema:
          return raw_json_content
  
      json_data = json.loads(raw_json_content)
      # Gets the custom metadata by name and parse the binary custom metadata into
      # human readable json content.
      for name, schema_file in custom_metadata_schema.items():
          idx, custom_metadata = _get_custom_metadata(
              metadata_buffer, name
          )
          if not custom_metadata:
              logging.info(
                  "No custom metadata with name %s in metadata flatbuffer.",
                  name,
              )
              continue
          _assert_file_exist(schema_file)
          with _open_file(schema_file, "rb") as f:
              custom_metadata_schema_content = f.read()
          if not parser.parse(custom_metadata_schema_content):
              raise ValueError(
                  "Cannot parse custom metadata schema. Reason: "
                  + parser.error
              )
          custom_metadata_json = _pywrap_flatbuffers.generate_text(
              parser, custom_metadata
          )
          json_meta = json_data["subgraph_metadata"][0][
              "custom_metadata"
          ][idx]
          json_meta["name"] = name
          json_meta["data"] = json.loads(custom_metadata_json)
      return json.dumps(json_data, indent=2)
  
imports: import copy
  import inspect
  import io
  import json
  import logging
  import os
  import shutil
  import sys
  import tempfile
  from typing import Dict, Optional
  import warnings
  import zipfile
  import flatbuffers
  from mediapipe.tasks.cc.metadata.python import _pywrap_metadata_version
  from mediapipe.tasks.metadata import metadata_schema_py_generated
  from mediapipe.tasks.metadata import schema_py_generated
  from mediapipe.tasks.python.metadata.flatbuffers_lib import _pywrap_flatbuffers
label_desc: Use image node_id 6 for calling a global function with example usage: convert_to_json(metadata_buffer, custom_metadata_schema) and returns: json, raw_json_content