def sort_response(response: Dict[str, Any]) -> OrderedDict:
    """
    Sort the keys in a JSON-RPC response object.

    This has no effect other than making it nicer to read. Useful in Python 3.5 only,
    dictionaries are already sorted in newer Python versions.

    Example::

        >>> json.dumps(sort_response({'id': 2, 'result': 5, 'jsonrpc': '2.0'}))
        {"jsonrpc": "2.0", "result": 5, "id": 1}

    Args:
        response: Deserialized JSON-RPC response.

    Returns:
        The same response, sorted in an OrderedDict.
    """
    root_order = ["jsonrpc", "result", "error", "id"]
    error_order = ["code", "message", "data"]
    req = OrderedDict(sorted(response.items(), key=lambda k: root_order.index(k[0])))
    if "error" in response:
        req["error"] = OrderedDict(
            sorted(response["error"].items(), key=lambda k: error_order.index(k[0]))
        )
    return req
def sort_response ( response : Dict [ str , Any ] ) -> OrderedDict : root_order = [ "jsonrpc" , "result" , "error" , "id" ] error_order = [ "code" , "message" , "data" ] req = OrderedDict ( sorted ( response . items ( ) , key = lambda k : root_order . index ( k [ 0 ] ) ) ) if "error" in response : req [ "error" ] = OrderedDict ( sorted ( response [ "error" ] . items ( ) , key = lambda k : error_order . index ( k [ 0 ] ) ) ) return req
Sort the keys in a JSON-RPC response object.

    This has no effect other than making it nicer to read. Useful in Python 3.5 only,
    dictionaries are already sorted in newer Python versions.

    Example::

        >>> json.dumps(sort_response({'id': 2, 'result': 5, 'jsonrpc': '2.0'}))
        {"jsonrpc": "2.0", "result": 5, "id": 1}

    Args:
        response: Deserialized JSON-RPC response.

    Returns:
        The same response, sorted in an OrderedDict.