def dict_to_json(xcol, ycols, labels, value_columns):
 json_data = dict()
 json_data['cols'] = [{'id': xcol, 'label': as_unicode(labels[xcol]), 'type': 'string'}]
 for ycol in ycols:
  json_data['cols'].append({'id': ycol, 'label': as_unicode(labels[ycol]), 'type': 'number'})
 json_data['rows'] = []
 for value in value_columns:
  row = {'c': []}
  if isinstance(value[xcol], datetime.date):
   row['c'].append({'v': str(value[xcol])})
  else:
   row['c'].append({'v': value[xcol]})
  for ycol in ycols:
   if value[ycol]:
    row['c'].append({'v': value[ycol]})
   else:
    row['c'].append({'v': 0})
  json_data['rows'].append(row)
 return json_data

def dict_to_json ( xcol , ycols , labels , value_columns ) : json_data = dict ( ) json_data [ 'cols' ] = [ { 'id' : xcol , 'label' : as_unicode ( labels [ xcol ] ) , 'type' : 'string' } ] for ycol in ycols : json_data [ 'cols' ] . append ( { 'id' : ycol , 'label' : as_unicode ( labels [ ycol ] ) , 'type' : 'number' } ) json_data [ 'rows' ] = [ ] for value in value_columns : row = { 'c' : [ ] } if isinstance ( value [ xcol ] , datetime . date ) : row [ 'c' ] . append ( { 'v' : str ( value [ xcol ] ) } ) else : row [ 'c' ] . append ( { 'v' : value [ xcol ] } ) for ycol in ycols : if value [ ycol ] : row [ 'c' ] . append ( { 'v' : value [ ycol ] } ) else : row [ 'c' ] . append ( { 'v' : 0 } ) json_data [ 'rows' ] . append ( row ) return json_data
converts a list of dicts from datamodel query results to google chart json data .