code: def serialize(value):
      """
      Serialize value to json-convertible object
      Ensures that all components of value can be serialized to json
      :param value: object to be serialized
      """
  
      def _serialize(val, _):
          if val is None:
              return val
          if isinstance(val, six.string_types) or isinstance(
              val, bytes
          ):
              return tools.to_utf8(val)
          if isinstance(val, enum.Enum):
              return str(val)
          if isinstance(val, six.integer_types) or type(val) in [
              float,
              bool,
          ]:
              return val
          if is_external(val):
              return dict(val)
          if isinstance(val, (date, datetime)):
              return repr(val)
          if is_coroutine(val):
              return None
          raise ValueError(
              "Cannot serialize value '{}' of type {}".format(
                  val, type(val)
              )
          )
  
      return apply(_serialize, value, apply_to_keys=True)
  
imports: from __future__ import absolute_import
  import re
  import sys
  import copy
  import logging
  from .None import tools
  from datetime import date, datetime
  import enum
  import six
label_desc: Use image node_id 3 for calling a global function with example usage: serialize(value) and returns: apply, val, tools, str, val, dict, repr, None