                  raise ValueError("JSON can't represent timezone-aware times.")
              representation = obj.isoformat()
              return representation
          elif isinstance(obj, datetime.timedelta):
              return six.text_type(obj.total_seconds())
          elif isinstance(obj, decimal.Decimal):
              # Serializers will coerce decimals to strings by default.
              return float(obj)
          elif isinstance(obj, uuid.UUID):
              return six.text_type(obj)
 
</s> remove             return six.text_type(obj)
 </s> add             return str(obj) </s> remove     elif isinstance(value, six.string_types):
 </s> add     elif isinstance(value, str): </s> remove     elif isinstance(val, six.string_types):
 </s> add     elif isinstance(val, str): </s> remove     return six.text_type(value)
 </s> add     return str(value) </s> remove         return super(JSONEncoder, self).default(obj)
 </s> add         return super().default(obj)
            return str(obj.total_seconds())
                  raise ValueError("JSON can't represent timezone-aware times.")
              representation = obj.isoformat()
              return representation
          elif isinstance(obj, datetime.timedelta):
            return str(obj.total_seconds())
          elif isinstance(obj, decimal.Decimal):
              # Serializers will coerce decimals to strings by default.
              return float(obj)
          elif isinstance(obj, uuid.UUID):
              return six.text_type(obj)
keep keep keep keep replace keep keep keep keep keep
 Dropped Python 2 compatibility. (#6615)

Thanks to Jon Dufresne (@jdufresne) for review.

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Rizwan Mansuri <Rizwan@webbyfox.com> 
rest_framework/utils/encoders.py