import collections


def parse_table_response(response):
    """
    Example:
        [
          {
            "rows": [
              [
                "PrimaryServer1",
                54.0
              ]
            ],
            "type": "table",
            "id": "a",
            "columns": [
              {
                "text": "device"
              },
              {
                "text": "tslast(metric)"
              }
            ]
          }
        ]

    :param response:   server response as json object
    :return:           a list of dictionaries where the key is column name and the value comes from the row
    """
    columns = response[0]['columns']
    rows = response[0]['rows']
    res = []
    for row in rows:
        rowdict = collections.OrderedDict()
        for (rc, column) in zip(row, columns):
            cn = column['text']
            rowdict[cn] = rc
        res.append(rowdict)
    return res