Bird
0
0

Which of the following is the correct syntax to read JSON data from a file file.json?

easy📝 Syntax Q3 of 15
Python - Structured Data Files

Which of the following is the correct syntax to read JSON data from a file file.json?

Awith open('file.json') as f: data = json.dumps(f)
Bwith open('file.json') as f: data = json.loads(f)
Cwith open('file.json') as f: data = json.dump(f)
Dwith open('file.json') as f: data = json.load(f)
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct function for reading JSON from file

    json.load() reads JSON data from a file object.
  2. Step 2: Understand difference with loads and dump functions

    json.loads() reads from a string, not a file; dump and dumps are for writing JSON.
  3. Final Answer:

    with open('file.json') as f: data = json.load(f) -> Option D
  4. Quick Check:

    Read JSON from file = json.load(file) [OK]
Quick Trick: Use json.load(file) to read JSON from a file object [OK]
Common Mistakes:
  • Using json.loads() on file object
  • Confusing dump and load functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes