Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load JSON data from a file.
Selenium Python
import json with open('data.json', '[1]') as file: data = json.load(file)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using write mode ('w') instead of read mode.
Using append mode ('a') which is for adding data.
✗ Incorrect
The file must be opened in read mode ('r') to load JSON data correctly.
2fill in blank
mediumComplete the code to access the 'username' field from loaded JSON data.
Selenium Python
username = data[1]'username'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets.
Using curly braces which define dictionaries, not access keys.
✗ Incorrect
JSON data loaded as a dictionary uses square brackets to access keys.
3fill in blank
hardFix the error in the code to correctly parse JSON string data.
Selenium Python
import json json_string = '{"key": "value"}' data = json.[1](json_string)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using json.load() on a string instead of a file.
Using json.dumps() which converts Python objects to JSON strings.
✗ Incorrect
Use json.loads() to parse a JSON string into a Python dictionary.
4fill in blank
hardFill both blanks to read JSON data and extract the 'password' field.
Selenium Python
with open('config.json', '[1]') as f: config = json.[2](f) password = config['password']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Opening the file in write mode.
Using json.loads() on a file object.
✗ Incorrect
Open the file in read mode ('r') and use json.load() to read JSON from the file object.
5fill in blank
hardFill all three blanks to load JSON data, access 'email', and assert it equals expected value.
Selenium Python
with open('user.json', '[1]') as file: user_data = json.[2](file) assert user_data['email'] [3] 'test@example.com'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Opening file in write mode.
Using json.loads() on a file object.
Using '=' instead of '==' in assert.
✗ Incorrect
Open file in read mode ('r'), use json.load() to parse, and assert equality with '=='.