Format output for json response.

def to_json(df, x, y, timeseries=False):
        """Format output for json response."""
        values = {k: [] for k in y}
        for i, row in df.iterrows():
            for yy in y:
                values[yy].append({
                    "x": row[x],
                    "y": row[yy]
                    })
        return {"result":  [values[k] for k in y], "date": timeseries}