Bird
0
0

Which of the following code snippets correctly reads JSON data from a file named testdata.json?

easy📝 Syntax Q3 of 15
Selenium Python - Data-Driven Testing
Which of the following code snippets correctly reads JSON data from a file named testdata.json?
Awith open('testdata.json') as f: data = json.loads(f)
Bwith open('testdata.json') as f: data = json.load(f)
Cdata = json.load('testdata.json')
Ddata = json.loads('testdata.json')
Step-by-Step Solution
Solution:
  1. Step 1: Open the file correctly

    Use with open('filename') as f: to open the file safely.
  2. Step 2: Use json.load() on the file object

    Pass the file object f to json.load() to parse JSON data.
  3. Final Answer:

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

    Open file + json.load(file) = correct syntax [OK]
Quick Trick: Use with open() and json.load(file) to read JSON [OK]
Common Mistakes:
  • Using json.loads() on file object
  • Passing filename string to json.load()
  • Not using with statement for file

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes