Bird
0
0

What is wrong with this HTTP triggered function that tries to return JSON?

medium📝 Debug Q7 of 15
GCP - Cloud Functions
What is wrong with this HTTP triggered function that tries to return JSON?
def json_response(request):
    return {'message': 'Success'}
ANo error, this is valid
BMissing import for JSON module
CFunction name must be 'main'
DReturns a dict instead of a valid HTTP response
Step-by-Step Solution
Solution:
  1. Step 1: Check return type

    Returning a dict directly is not a valid HTTP response in GCP functions.
  2. Step 2: Proper JSON response format

    Function should return a stringified JSON or use a response object with content-type.
  3. Final Answer:

    Returns a dict instead of a valid HTTP response -> Option D
  4. Quick Check:

    Return dict directly = invalid HTTP response [OK]
Quick Trick: Return JSON as string or response object, not raw dict [OK]
Common Mistakes:
  • Returning dict instead of JSON string
  • Assuming function name affects response
  • Missing content-type header

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes