code: def to_json(self, value, preserve_ro):
      
      if hasattr(value, 'to_json_dict'):
        return value.to_json_dict(preserve_ro)
      elif isinstance(value, dict) and self._atype == ApiConfig:
        return config_to_api_list(value)
      elif isinstance(value, datetime.datetime):
        return value.strftime(self.DATE_FMT)
      elif isinstance(value, list) or isinstance(value, tuple):
        if self._is_api_list:
          return ApiList(value).to_json_dict()
        else:
          return [ self.to_json(x, preserve_ro) for x in value ]
      else:
        return value
docs: Returns the JSON encoding of the given attribute value.
  
      If the value has a 'to_json_dict' object, that method is called. Otherwise,
      the following values are returned for each input type:
       - datetime.datetime: string with the API representation of a date.
       - dictionary: if 'atype' is ApiConfig, a list of ApiConfig objects.
       - python list: python list (or ApiList) with JSON encoding of items
       - the raw value otherwise