from flask import request


def request_wants_json():
    """ 
    See http://flask.pocoo.org/snippets/45
    """
    best = request.accept_mimetypes.best_match(['application/json', 'text/html'])

    return best == 'application/json' and \
        request.accept_mimetypes[best] > \
        request.accept_mimetypes['text/html']
