import json


def maybe_dumps(s):
    """
    If the given value is a json structure, encode it as a json
    string. Otherwise leave it as is.
    """
    if isinstance(s, (dict, list)):
        return json.dumps(s)
    return s