Bird
0
0

What does the json.dumps() function do in Python?

easy📝 Conceptual Q11 of 15
Python - Structured Data Files
What does the json.dumps() function do in Python?
AReads JSON data from a file
BConverts Python data into a JSON formatted string
CConverts JSON string back to Python data
DWrites Python data directly to a file
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of json.dumps()

    This function takes Python objects like dictionaries or lists and turns them into a JSON string.
  2. Step 2: Differentiate from other JSON functions

    json.loads() converts JSON strings back to Python objects, while dumps() does the opposite.
  3. Final Answer:

    Converts Python data into a JSON formatted string -> Option B
  4. Quick Check:

    Serialize = Python to JSON string [OK]
Quick Trick: Remember: dumps() means dump Python to JSON string [OK]
Common Mistakes:
  • Confusing dumps() with loads()
  • Thinking dumps() writes to a file
  • Assuming dumps() reads JSON data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes