def jsonxs(data, expr, action=ACTION_GET, value=None, default=None):
    """
    Get, set, delete values in a JSON structure. `expr` is a JSONpath-like
    expression pointing to the desired value. `action` determines the action to
    perform. See the module-level `ACTION_*` constants. `value` should be given
    if action is `ACTION_SET`. If `default` is set and `expr` isn't found,
    return `default` instead. This will override all exceptions.
    """
    tokens = tokenize(expr)

    # Walk through the list of tokens to reach the correct path in the data
    # structure.
    try:
        prev_path = None
        cur_path = data
        for token in tokens:
            prev_path = cur_path
            if not token in cur_path and action in [ACTION_SET, ACTION_MKDICT, ACTION_MKLIST]:
                # When setting values or creating dicts/lists, the key can be
                # missing from the data struture
               continue
            cur_path = cur_path[token]
    except Exception:
        if default is not None:
            return default
        else:
            raise

    # Perform action the user requested.
    if action == ACTION_GET:
        return cur_path
    elif action == ACTION_DEL:
        del prev_path[token]
    elif action == ACTION_SET:
        prev_path[token] = value
    elif action == ACTION_APPEND:
        prev_path[token].append(value)
    elif action == ACTION_INSERT:
        prev_path.insert(token, value)
    elif action == ACTION_MKDICT:
        prev_path[token] = {}
    elif action == ACTION_MKLIST:
        prev_path[token] = []
    else:
        raise ValueError("Invalid action: {}".format(action))
Get, set, delete values in a JSON structure. `expr` is a JSONpath-like
    expression pointing to the desired value. `action` determines the action to
    perform. See the module-level `ACTION_*` constants. `value` should be given
    if action is `ACTION_SET`. If `default` is set and `expr` isn't found,
    return `default` instead. This will override all exceptions.