Bird
0
0

Why is it important to use jsonify instead of json.dumps when serving sensor data as JSON API in Flask?

hard🧠 Conceptual Q10 of 15
Raspberry Pi - Web Server and API

Why is it important to use jsonify instead of json.dumps when serving sensor data as JSON API in Flask?

Ajson.dumps only works with lists, not dicts
Bjson.dumps is slower than jsonify
Cjsonify encrypts the data for security
Djsonify creates a proper Flask response with correct headers; json.dumps returns a string only
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between jsonify and json.dumps

    jsonify returns a Flask Response object with JSON content-type headers; json.dumps returns a JSON string without headers.
  2. Step 2: Importance for API clients

    Clients expect proper headers to parse JSON; jsonify ensures this, json.dumps does not.
  3. Final Answer:

    jsonify creates a proper Flask response with correct headers; json.dumps returns a string only -> Option D
  4. Quick Check:

    jsonify = Flask response with headers [OK]
Quick Trick: jsonify sets headers; json.dumps just makes string [OK]
Common Mistakes:
MISTAKES
  • Thinking json.dumps sets headers
  • Believing jsonify encrypts data
  • Confusing json.dumps limitations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes