title: How do I return a JSON array with Bottle?
body: <p>I'm writing an API using <a href="http://bottlepy.org">Bottle</a>, which so far has been fantastic. However, I've run up against a small hurdle when trying to return a JSON array. Here's my test app code:</p>
  
  <pre><code>from bottle import route, run
  
  @route('/single')
  def returnsingle():
      return { "id": 1, "name": "Test Item 1" }
  
  @route('/containsarray')
  def returncontainsarray():
      return { "items": [{ "id": 1, "name": "Test Item 1" }, { "id": 2, "name": "Test Item 2" }] }
  
  @route('/array')
  def returnarray():
      return [{ "id": 1, "name": "Test Item 1" }, { "id": 2, "name": "Test Item 2" }]
  
  run(host='localhost', port=8080, debug=True, reloader=True)
  </code></pre>
  
  <p>When I run this and request each route, I get the JSON responses I'd expect from the first two routes:</p>
  
  <p><strong>/single</strong></p>
  
  <pre><code>{ id: 1, name: "Test Item 1" }
  </code></pre>
  
  <p><strong>/containsarray</strong></p>
  
  <pre><code>{ "items": [ { "id": 1, "name": "Test Item 1" }, { "id": 2, "name": "Test Item 2" } ] }
  </code></pre>
  
  <p>So, I had expected returning a list of dictionaries to create the following JSON response:</p>
  
  <pre><code>[ { "id": 1, "name": "Test Object 1" }, { "id": 2, "name": "Test Object 2" } ]
  </code></pre>
  
  <p>But requesting the <code>/array</code> route just results in an error. What am I doing wrong, and how can I return a JSON array in this manner?</p>