Which return statement produces the JSON object {"cat_9k": "FXS1932Q2SE"}?
Choose an answer
Tap an option to check your answer.
Correct answer: return (json.dumps({d['hostname']: d['serialNumber'] for d in json.loads(test_json)['response']})).
Why this is the answer
The correct option uses a dictionary comprehension to iterate through the response list, creating key-value pairs where the key is the hostname and the value is the serialNumber. json.loads(testjson) correctly parses the initial JSON string into a Python object. Finally, json.dumps() converts the resulting Python dictionary back into a JSON string. The other options contain syntax errors or incorrect function usage: The second option has an incorrect dictionary comprehension syntax (for d in ...: d['hostname']: d['serialNumber']). The third and fourth options incorrectly use json.loads() on the dictionary comprehension result, which expects a JSON string, not a Python dictionary. They also incorrectly use json.dumps() on testjson before accessing ['response'].
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