Bird
0
0

This Python code tries to load JSON data but causes an error:

medium📝 Debug Q6 of 15
Python - Structured Data Files
This Python code tries to load JSON data but causes an error:
import json
bad_json = '{"name": "Bob", age: 25}'
data = json.loads(bad_json)

What is the main problem?
AUsing single quotes instead of double quotes
BMissing quotes around the key 'age'
CJSON cannot have numbers as values
Djson.loads cannot parse dictionaries
Step-by-Step Solution
Solution:
  1. Step 1: Check JSON syntax rules for keys

    JSON keys must be strings in double quotes; here 'age' is missing quotes.
  2. Step 2: Identify the cause of parsing error

    Missing quotes cause json.loads to raise a syntax error.
  3. Final Answer:

    Missing quotes around the key 'age' -> Option B
  4. Quick Check:

    JSON keys need quotes [OK]
Quick Trick: Always quote JSON keys with double quotes [OK]
Common Mistakes:
  • Thinking single quotes are allowed for keys
  • Believing numbers can't be JSON values
  • Assuming json.loads can't parse dicts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes