import json


def clean_sql_json(x):
    """Cleans up JSON produced by SQL Server by reducing this pattern:
        [{"Key": [{"Key": "Value"}]}]
    to this:
        [{'Key': ['Value']}]

    Also removes duplicates (and ordering) from the reduced list.
    Returns an object, not JSON.
    """

    datas = json.loads(x)

    for data in datas:
        for key, value in data.items():
            if (isinstance(value, list)
                    and isinstance(value[0], dict)
                    and len(value[0]) == 1
                    ):
                data[key] = list({
                    list(item.values())[0]
                    for item in value
                })

    return datas