import json


def transform_kval_json_str(st):
    """
    BQ + python transforms hist `values` attribute from
    {"k": v} => [{'key': k, 'value': v}].
    This undoes this.
    """
    d = json.loads(st)
    values = d.pop("values")
    values_dct = {str(d["key"]): d["value"] for d in values}
    d["values"] = values_dct
    return json.dumps(d)