def apply_projection(projection, value):
    """Apply projection."""
    if isinstance(value, Sequence):
        # Apply projection to each item in the list.
        return [
            apply_projection(projection, item)
            for item in value
        ]
    elif not isinstance(value, Mapping):
        # Non-dictionary values are simply ignored.
        return value

    # Extract projection for current level.
    try:
        current_projection = [p[0] for p in projection]
    except IndexError:
        return value

    # Apply projection.
    for name in list(value.keys()):
        if name not in current_projection:
            value.pop(name)
        elif isinstance(value[name], dict):
            # Apply projection recursively.
            value[name] = apply_projection(
                [p[1:] for p in projection if p[0] == name],
                value[name]
            )

    return value
Apply projection.