Bird
0
0

Given the JSON file data.json contains:

medium📝 Predict Output Q4 of 15
Selenium Python - Data-Driven Testing
Given the JSON file data.json contains:
{"user": "admin", "pass": "1234"}

What will be the output of this code?
import json
with open('data.json') as f:
    data = json.load(f)
print(data['user'])
Adata
B1234
CKeyError
Dadmin
Step-by-Step Solution
Solution:
  1. Step 1: Load JSON data from file

    The code reads the JSON file and stores it as a dictionary in data.
  2. Step 2: Access the 'user' key in the dictionary

    Printing data['user'] outputs the value associated with 'user', which is "admin".
  3. Final Answer:

    admin -> Option D
  4. Quick Check:

    Access JSON key 'user' = admin [OK]
Quick Trick: Access JSON keys like dictionary keys in Python [OK]
Common Mistakes:
  • Expecting print(data['pass'])
  • Confusing json.load() with string output
  • KeyError if key misspelled

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes