Bird
Raised Fist0

You have a Python list data = [1, 2, 3]. How do you serialize it to a JSON string and then deserialize it back to a Python list?

hard🚀 Application Q8 of Q15
Python - Structured Data Files
You have a Python list data = [1, 2, 3]. How do you serialize it to a JSON string and then deserialize it back to a Python list?
Ajson.dumps(data) then json.loads()
Bjson.loads(data) then json.dumps()
Cjson.dump(data) then json.load()
Djson.load(data) then json.dump()
Step-by-Step Solution
Solution:
  1. Step 1: Serialize Python list to JSON string

    Use json.dumps(data) to convert the list to a JSON string.
  2. Step 2: Deserialize JSON string back to Python list

    Use json.loads() on the JSON string to get back the Python list.
  3. Final Answer:

    json.dumps(data) then json.loads() -> Option A
  4. Quick Check:

    Serialize with dumps(), deserialize with loads() [OK]
Quick Trick: dumps() to string, loads() back to object [OK]
Common Mistakes:
MISTAKES
  • Using load() and dump() without files
  • Confusing order of functions
  • Passing Python object directly to loads()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes