Bird
Raised Fist0

What will be the output of this Python code using JSON to load data?

medium📝 Predict Output Q13 of Q15
Python - Structured Data Files
What will be the output of this Python code using JSON to load data?
import json
json_data = '{"city": "Paris", "population": 2148327}'
data = json.loads(json_data)
print(data["city"])
A2148327
B{"city": "Paris", "population": 2148327}
CParis
DError: KeyError
Step-by-Step Solution
Solution:
  1. Step 1: Understand json.loads function

    json.loads converts a JSON string into a Python dictionary.
  2. Step 2: Access the dictionary value by key

    data["city"] accesses the value for key "city", which is "Paris".
  3. Final Answer:

    Paris -> Option C
  4. Quick Check:

    json.loads + dict access = value [OK]
Quick Trick: json.loads turns JSON string into dict; access keys normally [OK]
Common Mistakes:
MISTAKES
  • Printing the original JSON string instead of parsed data
  • Confusing keys and values
  • Expecting a list instead of a dictionary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes