import jinja2
import json


def jsvalattr(value):
    """Format a value as json, for use in an attribute value.

    """
    assert not isinstance(value, jinja2.runtime.Undefined)
    return json.dumps(value, indent=None, separators=(',', ':'))