<p dir="auto">Consider <code class="notranslate">jsonify()</code>cation of a dictionary contained in a list:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="print flask.__version__
print repr(flask.jsonify([{&quot;a&quot;: 1, &quot;b&quot;: 2}]).data)"><pre class="notranslate"><span class="pl-k">print</span> <span class="pl-s1">flask</span>.<span class="pl-s1">__version__</span>
<span class="pl-k">print</span> <span class="pl-en">repr</span>(<span class="pl-s1">flask</span>.<span class="pl-en">jsonify</span>([{<span class="pl-s">"a"</span>: <span class="pl-c1">1</span>, <span class="pl-s">"b"</span>: <span class="pl-c1">2</span>}]).<span class="pl-s1">data</span>)</pre></div>
<p dir="auto">With the following output:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="0.10.1
'{\n  &quot;a&quot;: &quot;b&quot;\n}'"><pre class="notranslate"><span class="pl-c1">0.10</span>.<span class="pl-c1">1</span>
<span class="pl-s">'{<span class="pl-cce">\n</span>  "a": "b"<span class="pl-cce">\n</span>}'</span></pre></div>
<p dir="auto"><code class="notranslate">jsonify()</code> has -- without complaining -- mangled the data into something really not useful: The original dictionary values are gone, and the <code class="notranslate">"b"</code> key suddenly is a value.</p>
<p dir="auto">I appreciate that top-level array elements are not allowed to be created in Flask's <code class="notranslate">jsonify()</code> implementation (<a href="http://flask.pocoo.org/docs/0.10/security/#json-security" rel="nofollow">http://flask.pocoo.org/docs/0.10/security/#json-security</a>). Also, there are for sure straight-forward strategies for solving this in application code, for example by wrapping the list in a dictionary: <code class="notranslate">jsonify({"items": collection})</code>.</p>
<p dir="auto">However, in the Python world we do not find it very often that an entity accepts invalid input and produces garbled output without complaining. Also, it looks like <code class="notranslate">jsonify()</code> once raised an exception when provided a list (at least in 2011 it did raise a <code class="notranslate">TypeError</code>: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="604631" data-permission-text="Title is private" data-url="https://github.com/pallets/flask/issues/170" data-hovercard-type="issue" data-hovercard-url="/pallets/flask/issues/170/hovercard" href="https://github.com/pallets/flask/issues/170">#170</a>).</p>
<p dir="auto">Should we raise an exception again or is the current behavior carefully designed with a focus on performance? I mean, it is unlikely that this data mangling ends up in a production environment (a developer really should realize that <code class="notranslate">jsonify()</code> produces garbage in this case , like I did).</p>
<p dir="auto">ECMAscript 5 changed behavior of Array literals. That part of the documentation is outdated by now. We should check what browsers are affected by this and update the docs accordingly.</p>