Given the router's JSON API response, which Python snippet prints the hostname value?
Choose an answer
Tap an option to check your answer.
Correct answer: json_data = response,json() print(json_data['response'][0]['hostname']).
Why this is the answer
The correct snippet jsondata = response.json(); print(jsondata['response'][0]['hostname']) works because response.json() directly parses the JSON response into a Python dictionary or list. The JSON structure provided (implicitly) shows 'response' as a key whose value is a list, and the first element of that list (index [0]) is a dictionary containing the 'hostname' key. The other options are incorrect for various reasons: jsondata = json.loads(response.text) is a valid way to parse JSON, but the subsequent indexing ['response']['family']['hostname'] is incorrect if 'family' is not a direct key within the 'response' object or if 'response' is a list. print(jsondata[response][0][hostname]) uses incorrect syntax for dictionary/list access, as response and hostname are treated as variables instead of string keys. print(jsondata['response'][family][hostname]) also incorrectly treats family and hostname as variables instead of string keys.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed