@app.route("/thread/<int:thread_id>/posts_json") def posts_json(thread_id): posts = db.execute( "SELECT id, name, message, created_at FROM posts WHERE thread_id=? ORDER BY id", (thread_id,) ).fetchall() return jsonify([dict(row) for row in posts])