Skip to content


Fixes issue #495. #502

wants to merge 2 commits into from

2 participants


Bam! Also collapses multiple json.dumps() and response_class() statements into a single one, respectively. This is done because it will come in handy in the future when making changes to the arguments to those function calls.


Thanks for the pull request. Here's an alternative:

As it stands right now, we may pull JSONP from the Flask core, and prefer leaving it for an extension. The reasons being:

  1. the API for the padded jsonify is a bit awkward with bool or str as possible values, and the str case being either a request arg or a function name
  2. modern browsers do not need JSONP
  3. JSONP would benefit from CSRF protection, which could use the Flask-SeaSurf extension

JSONP support is currently not released in Flask, only in master.

@jfinkels jfinkels added a commit to jfinkels/flask that referenced this pull request
@jfinkels jfinkels Reverted changes made by too-eager merge with pull request #502. 1e2aae2

JSONP removed. Note discussion here on a Flask-JSONP extension.

@rduplain rduplain closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 26, 2012
  1. @jfinkels

    Fixes issue #495.

    jfinkels committed
  2. @jfinkels
Showing with 14 additions and 11 deletions.
  1. +2 −0 CHANGES
  2. +12 −11 flask/
@@ -8,6 +8,8 @@ Version 0.9
Relase date to be decided, codename to be chosen.
+- The :func:`flask.jsonify` now correctly does *not* pad its JSON response with
+ "jsonp" when the ``padded`` keyword argument is ``False``.
- The :func:`flask.Request.on_json_loading_failed` now returns a JSON formatted
response by default.
- The :func:`flask.url_for` function now can generate anchors to the
23 flask/
@@ -134,18 +134,19 @@ def get_current_user():
if __debug__:
- if 'padded' in kwargs:
- if isinstance(kwargs['padded'], str):
- callback = request.args.get(kwargs['padded']) or 'jsonp'
+ padded = kwargs.pop('padded', False)
+ indent = None if request.is_xhr or padded else 2
+ mimetype = 'application/json'
+ content = json.dumps(dict(*args, **kwargs), indent=indent)
+ if padded:
+ mimetype = 'application/javascript'
+ if isinstance(padded, str):
+ callback = request.args.get(padded) or 'jsonp'
- callback = request.args.get('callback') or \
- request.args.get('jsonp') or 'jsonp'
- del kwargs['padded']
- json_str = json.dumps(dict(*args, **kwargs), indent=None)
- content = str(callback) + "(" + json_str + ")"
- return current_app.response_class(content, mimetype='application/javascript')
- return current_app.response_class(json.dumps(dict(*args, **kwargs),
- indent=None if request.is_xhr else 2), mimetype='application/json')
+ callback = (request.args.get('callback') or
+ request.args.get('jsonp') or 'jsonp')
+ content = '%s(%s)' % (str(callback), content)
+ return current_app.response_class(content, mimetype=mimetype)
def make_response(*args):
Something went wrong with that request. Please try again.