exam questions

Exam 350-401 All Questions

View all questions & answers for the 350-401 exam

Exam 350-401 topic 1 question 439 discussion

Actual exam question from Cisco's 350-401
Question #: 439
Topic #: 1
[All 350-401 Questions]

Based on the router's API output in JSON format below, which Python code will display the value of the `hostname` key?

  • A. json_data = response,json() print(json_data['response'][0]['hostname'])
  • B. json_data = json.loads(response.text) print(json_data['response']['family']['hostname'])
  • C. json_data = json.loads(response.text) print(json_data[response][0][hostname])
  • D. json_data = response.json() print(json_data['response'][family][hostname'])
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Caradum
Highly Voted 2 years, 5 months ago
A must be correct. "response,json()" the comma must be a typo and should be a dot, because all other answer are clearly wrong. B & D make the same mistake: 'hostname' is not a child element of 'family'. C has no semicolons in the square brackets.
upvoted 9 times
...
AbdullahMohammad251
Most Recent 7 months, 4 weeks ago
Selected Answer: A
"Json.loads(response.text)" and "response.json()" --> both methods are used to convert a Json string into a python dictionary. Options A,C & D are incorrect: C& D are missing quotation marks A&D are using the "family" key to access the value for the "hostname" key, but "hostname" key isn't a nested key of the "family" key.
upvoted 1 times
AbdullahMohammad251
7 months, 4 weeks ago
Correction: I meant B & D are using the "family" key to access the value for the "hostname" key, but "hostname" key isn't a nested key of the "family" key. Option B,C & D are incorrect.
upvoted 1 times
...
...
[Removed]
11 months, 2 weeks ago
Selected Answer: A
A is correct
upvoted 1 times
...
LanreDipeolu
1 year, 8 months ago
{ "response":[{ "family": "Switches", "macAddress": "00:4141:43:07:00", "hostname": "SwitchIDF14", "upTime": "352 days, 6:17:26:10", "lastUpdate": "2020-07-12 21:15:29", }] } print ("the family name is ", json_data['response'][0]['family']) the family name is Switches or print ("the hostname name is ", json_data['response'][0]['hostname']) the hostname name is SwitchIDF14 A is the answer
upvoted 2 times
...
msstanick
1 year, 10 months ago
Selected Answer: A
It is A indeed. First we need to make a python dict so response.json() and use it for printing. json_data = { "response": [{ "family": "Switches", "macAddress": "ff:ff:ff:ff:ff:ff", "hostname": "SwitchDF14" }] } print("The hostname is: ",json_data['response'][0]['hostname']) The hostname is: SwitchDF14
upvoted 1 times
...
landgar
2 years, 3 months ago
Selected Answer: A
A is right, but with response.json()
upvoted 2 times
...
attiko
2 years, 6 months ago
Selected Answer: A
A is the correct answer, verified by writing a script on my PC
upvoted 1 times
...
jhonelo2011
2 years, 7 months ago
Selected Answer: A
It is A, the output was generated from an API get request using "requests" library. https://www.geeksforgeeks.org/response-json-python-requests/
upvoted 3 times
...
kebkim
2 years, 7 months ago
I guess B is correct.
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago