Bird
0
0

What will be the output when this Flask route is accessed via GET?

medium📝 Predict Output Q4 of 15
Raspberry Pi - Web Server and API
What will be the output when this Flask route is accessed via GET?
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/temp', methods=['GET'])
def temp():
    data = {'temperature': 22.5}
    return jsonify(data)
Atemperature: 22.5
BError: jsonify not defined
C<temperature>22.5</temperature>
D{"temperature": 22.5}
Step-by-Step Solution
Solution:
  1. Step 1: Understand jsonify output

    jsonify converts Python dict to JSON string with correct headers.
  2. Step 2: Check returned data format

    Returned JSON string is {"temperature": 22.5} as JSON format.
  3. Final Answer:

    {"temperature": 22.5} -> Option D
  4. Quick Check:

    Flask jsonify output = JSON string [OK]
Quick Trick: jsonify returns JSON string from dict in Flask [OK]
Common Mistakes:
MISTAKES
  • Expecting plain text instead of JSON
  • Confusing JSON with XML
  • Missing import of jsonify

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes