def METHOD_NAME(response, fields, name=None, bom=False):
    u'''Context manager for writing UTF-8 JSON data to response
    :param response: file-like or response-like object for writing
        data and headers (response-like objects only)
    :param fields: list of datastore fields
    :param name: file name (for headers, response-like objects only)
    :param bom: True to include a UTF-8 BOM at the start of the file
    '''
    if hasattr(response, u'headers'):
        response.headers['Content-Type'] = (
            b'application/json; charset=utf-8')
        if name:
            response.headers['Content-disposition'] = (
                u'attachment; filename="{name}.json"'.format(
                    name=encode_rfc2231(name)))
    if bom:
        response.stream.write(BOM_UTF8)
    response.stream.write(
        six.ensure_binary(u'{\n  "fields": %s,\n  "records": [' % dumps(
            fields, ensure_ascii=False, separators=(u',', u':'))))
    yield JSONWriter(response.stream)
    response.stream.write(b'\n]}\n')