code: def serialize_value(value, extended=False):
      """Serializes the given value.
  
      Args:
          value: the value
          extended (False): whether to serialize extended JSON constructs such as
              ObjectIDs, Binary, etc. into JSON format
  
      Returns:
          the serialized value
      """
      if isinstance(value, SON):
          return value
  
      if hasattr(value, "to_dict") and callable(value.to_dict):
          # EmbeddedDocumentField
          return value.to_dict(extended=extended)
  
      if isinstance(value, (bool, np.bool_)):
          # BooleanField
          return bool(value)
  
      if isinstance(value, numbers.Integral):
          # IntField
          return int(value)
  
      if isinstance(value, numbers.Number):
          # FloatField
          return float(value)
  
      if isinstance(value, ObjectId) and extended:
          return {"$oid": str(value)}
  
      if type(value) is date:
          # DateField
          return datetime(
              value.year, value.month, value.day, tzinfo=pytz.utc
          )
  
      if isinstance(value, np.ndarray):
          # VectorField/ArrayField
          binary = Binary(fou.serialize_numpy_array(value))
          if not extended:
              return binary
  
          # @todo can we optimize this?
          return json.loads(json_util.dumps(binary))
  
      if isinstance(value, (list, tuple)):
          # ListField
          return [serialize_value(v, extended=extended) for v in value]
  
      if isinstance(value, dict):
          # DictField
          return {
              k: serialize_value(v, extended=extended)
              for k, v in value.items()
          }
  
      return value
  
imports: from datetime import date, datetime
  import inspect
  import json
  import numbers
  import six
  import sys
  from bson import Binary, json_util, ObjectId, SON
  import numpy
  import pytz
  import fiftyone
  import fiftyone.core.fields
  import fiftyone.core.media
  import fiftyone.core.utils
label_desc: Use image node_id 1 for calling a global function with example usage: serialize_value(value, extended) and returns: value, value, value, bool, int, float, dict, datetime, json, unknown, unknown, binary