Bird
Raised Fist0

Why might json.loads() fail when deserializing a JSON string that contains Python-specific data types like tuples or sets?

hard🧠 Conceptual Q10 of Q15
Python - Structured Data Files
Why might json.loads() fail when deserializing a JSON string that contains Python-specific data types like tuples or sets?
ABecause json.loads() only works with strings, not tuples or sets
BBecause json.loads() requires a file, not a string
CBecause tuples and sets are automatically converted to lists
DBecause JSON format does not support tuples or sets natively
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSON data types

    JSON supports basic types like strings, numbers, arrays (lists), objects (dicts), but not Python-specific types like tuples or sets.
  2. Step 2: Effect on deserialization

    If a JSON string tries to represent tuples or sets, json.loads() cannot parse them because they are not valid JSON types.
  3. Final Answer:

    Because JSON format does not support tuples or sets natively -> Option D
  4. Quick Check:

    JSON lacks tuples/sets support [OK]
Quick Trick: JSON supports only basic types, not tuples or sets [OK]
Common Mistakes:
MISTAKES
  • Thinking json.loads() converts tuples/sets automatically
  • Confusing string input with data types
  • Assuming json.loads() reads files only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes