code: def json_serialize(obj):
      
      if isinstance(obj, datetime):
          return obj.isoformat()
  
      if hasattr(obj, 'id'):
          return jsonify(obj.id)
  
      if hasattr(obj, 'name'):
          return jsonify(obj.name)
  
      raise TypeError('{0} is not JSON serializable'.format(obj))
docs: Simple generic JSON serializer for common objects.