Bird
0
0

Consider this Python code:

medium📝 Predict Output Q5 of 15
Python - Structured Data Files
Consider this Python code:
import json
json_str = '{"valid": true, "items": [1, 2, 3]}'
obj = json.loads(json_str)
print(len(obj["items"]))

What is the output?
A1
Btrue
CError: invalid JSON
D3
Step-by-Step Solution
Solution:
  1. Step 1: Parse JSON string into Python object

    json.loads converts JSON string to Python dict; boolean true becomes True in Python.
  2. Step 2: Access the list and get its length

    obj["items"] is the list [1, 2, 3], so len(...) returns 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Length of list in JSON = 3 [OK]
Quick Trick: JSON true becomes Python True; lists keep length [OK]
Common Mistakes:
  • Confusing JSON true with string 'true'
  • Expecting boolean output instead of length
  • Thinking JSON parsing fails here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes