code: def to_json(obj, seen=None):
      
  
      if not seen:
          seen = []
  
      properties = list(class_mapper(type(obj)).iterate_properties)
      relationships = [
          p.key for p in properties if type(p) is RelationshipProperty
      ]
      attrs = [
          p.key for p in properties if p.key not in relationships
      ]
  
      d = dict([(attr, getattr(obj, attr)) for attr in attrs])
  
      for attr in relationships:
          d[attr] = expand(obj, getattr(obj, attr), seen)
  
      return d
docs: Returns a dict representation of the object.
  
      Recursively evaluates to_json(...) on its relationships.