from typing import OrderedDict


def ascii_encode_dict(item):
    """
    Support method to ensure that JSON is converted to ascii since unicode
    identifiers, in particular, can cause problems
    """
    if isinstance(item, dict):
        return OrderedDict(
            (ascii_encode_dict(key), ascii_encode_dict(item[key]))
            for key in sorted(item.keys()))
    elif isinstance(item, list):
        return [ascii_encode_dict(element) for element in item]
    elif isinstance(item, str):
        return item.encode('ascii')
    else:
        return item