title: Serialize SQLAlchemy output to a JSON including column names
body: <p>I've decided to migrate my Django project to work with SqlAlchemy instead of Django ORM and I'm trying to serialize my SqlAlchemy output to a JSON which contains column names.</p>
  
  <p>In Django I had the following code:</p>
  
  <pre><code>logs = Log.objects.values('log_timestamp', 'message', 'exception', 'level__level', 'job_info__job_name', 'machine', 'user', 'job_report__id').filter(job_info__app_id = app_id).order_by('-time_added')[:1]
  logs = json.dumps(list(logs), default=views_utils.default_json_serializer)
  print(logs)
  </code></pre>
  
  <p>and here an output example (contains column names):</p>
  
  <pre><code>[{"user": "user", "level__level": "INFO", "message": "this is a message", "log_timestamp": null, "job_info__job_name": "MongoDB_Maintenance", "exception": "exception details", "machine": "machine", "job_report__id": 65}]
  </code></pre>
  
  <p>Here is my SqlAlchemy code:</p>
  
  <pre><code>res = session.query(func.DATETIME(LogObj.time_added), LogObj.message, LogObj.exception, LogLevelObj.level, LogObj.machine, LogObj.user).\
                    join(PeriodicJobInfoObj, LogLevelObj, LogObj,aliased=True).\
                    filter(PeriodicJobInfoObj.app_id == app_id).\
                    order_by(desc(LogObj.time_added))[:1]
  res = json.dumps(res, default=views_utils.default_json_serializer)
  print(res)
  </code></pre>
  
  <p>The output does not contain column names:</p>
  
  <pre><code>[["2015-09-28 15:36:33", "this is a message", "exception details", "CRITICAL", "machine", "user"]]
  </code></pre>
  
  <p>default_json_serializer code:</p>
  
  <pre><code>def default_json_serializer(obj):
      """Default JSON serializer."""
      import calendar, datetime
  
      if isinstance(obj, datetime.datetime):
          if obj.utcoffset() is not None:
              obj = obj - obj.utcoffset()
      millis = int(
          calendar.timegm(obj.timetuple()) * 1000 +
          obj.microsecond / 1000
      )
      return millis
  </code></pre>
  
  <p>How can I achieve similar output like Django does?
  (working with Python 3.4.2)</p>