from typing import Union
from typing import List
from typing import Any
from typing import Dict
import hashlib
import json


def json_encode_hash(obj: Union[List[Any], Dict[str, Any]]) -> str:
    """Json encode the object and take MD5 hash with sorted keys."""
    obj_hash = hashlib.md5()
    # We need to sort arguments so {'a': 1, 'b': 2} is
    # the same as {'b': 2, 'a': 1}
    encoded = json.dumps(obj, sort_keys=True).encode()
    obj_hash.update(encoded)
    return obj_hash.hexdigest()