code: def config_to_json(cls, config_obj):
      json_result = {}
      if not hasattr(cls, "_fields"):
          raise IncorrectTypeError(f"{cls} is not a valid config class")
      for field, f_cls in cls.__annotations__.items():
          value = getattr(config_obj, field)
          try:
              json_result[field] = _value_to_json(f_cls, value)
          except Exception as e:
              cls_name = getattr(cls, "__name__", cls)
              raise ValueSerializationError(
                  f"Failed to serialise the config field '{field}' of class {cls_name}"
              ) from e
      return json_result
  
imports: from enum import Enum
  from typing import Any, Dict, List, Tuple, Type, Union
  from pytext.common.utils import eprint
  from .component import Registry
  from .config_adapter import upgrade_to_latest
  from .pytext_config import PyTextConfig
label_desc: Use image node_id 15 for calling a global function with example usage: config_to_json(cls, config_obj) and returns: json_result