import json
def errors_to_json(errors):
    Convert a Form error list to JSON::
        >>> f = SomeForm(...)
        >>> errors_to_json(f.errors)
        {'field': ['This field is required']}
    # Force error strings to be un-lazied.
    return json.dumps(
            (k, map(unicode, v))
            for (k,v) in errors.iteritems()

It's not as simple as json.dumps(form.errors) because form.errors is an ErrorList object that simplejson won't know how to dump.

Nor it is just json.dumps(dict(form.errors)) because error strings are lazy string objects that, again, simplejson won't dump.