import json
import click


def validate_filter(ctx, param, value):
    """Try to parse the given filter as a JSON string."""
    try:
        if value:
            return json.loads(value)
    except ValueError:
        raise click.BadParameter('filters need to be in JSON format')