Recall & Review
beginner
What Python module is used to work with JSON files?
The
json module is used to read from and write to JSON files in Python.Click to reveal answer
beginner
How do you read JSON data from a file in Python?
Use
json.load(file_object) after opening the file in read mode.Click to reveal answer
beginner
How do you write Python data to a JSON file?
Use
json.dump(data, file_object) after opening the file in write mode.Click to reveal answer
intermediate
What is the difference between
json.load() and json.loads()?json.load() reads JSON data from a file object, while json.loads() reads JSON data from a string.Click to reveal answer
beginner
Why is it important to open JSON files with the correct mode?
Opening a file in the wrong mode (e.g., reading in write mode) causes errors. Use 'r' for reading and 'w' for writing to handle JSON files properly.
Click to reveal answer
Which function reads JSON data from a file in Python?
✗ Incorrect
json.load() reads JSON data from a file object.Which mode should you use to open a JSON file for writing?
✗ Incorrect
Use
'w' mode to write to a file, which overwrites existing content.What does
json.dumps() do?✗ Incorrect
json.dumps() converts Python objects into JSON formatted strings.If you have a JSON string, which function converts it to Python data?
✗ Incorrect
json.loads() parses a JSON string into Python data.What happens if you try to read a JSON file opened in write mode?
✗ Incorrect
Opening a file in write mode and trying to read causes an error because the file is not readable in that mode.
Explain the steps to read JSON data from a file in Python.
Think about how you open files and use the json module.
You got /3 concepts.
Describe how to save Python data as JSON in a file.
Remember to convert Python data to JSON format and write it.
You got /3 concepts.