Performance: JSON response formatting
MEDIUM IMPACT
This affects how quickly the server sends data and how fast the browser can parse and render the response.
from flask import Flask, jsonify app = Flask(__name__) @app.route('/data') def data(): data = {'name': 'Alice', 'age': 30, 'city': 'Wonderland'} return jsonify(data) # compact JSON response
from flask import Flask, Response import json app = Flask(__name__) @app.route('/data') def data(): data = {'name': 'Alice', 'age': 30, 'city': 'Wonderland'} json_str = json.dumps(data, indent=4) # pretty print with spaces return Response(json_str, mimetype='application/json')
| Pattern | Payload Size | Network Transfer | Parsing Time | Verdict |
|---|---|---|---|---|
| Pretty Printed JSON | Large (extra spaces/newlines) | Longer transfer | Longer parse time | [X] Bad |
| Compact JSON with jsonify | Smaller (no extra whitespace) | Faster transfer | Faster parse time | [OK] Good |