title: How to serialize complex objects to JSON with Flask
body: <p>I'm new with Flask, and I'm having some problem trying to return an object which contains another object instance as field, like the follows:</p>
  
  <pre><code>class Park(object):
      park_id = 0
      address = ""
      services = []
      position = None
  
      def __init__(self, park_id, address, services, latitude, longitude):
          self.park_id = park_id
          self.address = address
          self.services = services
          self.position = Point(latitude, longitude)
  </code></pre>
  
  <p>where the Point class is simply the follow:</p>
  
  <pre><code>class Point(object):
      latitude = None
      longitude = None
  
      def __init__(self, latitude, longitude):
          self.latitude = latitude
          self.longitude = longitude
  </code></pre>
  
  <p>when I try to return a Park instance</p>
  
  <pre><code>@app.route('/')
  def test():
      park = Park(....)
      return jsonify(park])
  </code></pre>
  
  <p>I obtain this error: <code>TypeError: Object of type 'Park' is not JSON serializable</code>. </p>