def sortkey(key):
    """
    Helper method for sorting JSON paths.

    Treat keys as lowercase, prefer keys with less path segments.

    :param str key: Key to be sorted.
    :return: Key in sortable format.
    :rtype: tuple
    """
    return len(key.path), '/'.join(str(key.path)).lower()
