Bird
0
0

Given the JSON file user.json with content:

medium📝 Predict Output Q13 of 15
Selenium Python - Data-Driven Testing
Given the JSON file user.json with content:
{"username": "testuser", "password": "pass123"}

and the code:
import json
with open('user.json') as f:
    data = json.load(f)
print(data['username'])

What will be the output?
A{'username': 'testuser', 'password': 'pass123'}
Bpass123
Ctestuser
DKeyError
Step-by-Step Solution
Solution:
  1. Step 1: Load JSON data into dictionary

    The json.load(f) reads the JSON file and converts it into a Python dictionary with keys 'username' and 'password'.
  2. Step 2: Access dictionary value by key

    data['username'] accesses the value 'testuser' from the dictionary.
  3. Final Answer:

    testuser -> Option C
  4. Quick Check:

    data['username'] = 'testuser' [OK]
Quick Trick: Access JSON keys like dictionary keys [OK]
Common Mistakes:
  • Printing the whole dictionary instead of key value
  • Using wrong key causing KeyError
  • Confusing json.load() with json.loads()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes