350-901 practice question 23 of 35

{'lat': 37.4180951010362, 'lng': -122.098531723022, 'address': '', 'serial': 'Q2HP-F5K5-F98Q', 'mac': '88:15:44:ea:f5:bf', 'lanIp': '10.10.10.15'…

Full set: 430 questions

Domain Software Development and Design

{'lat': 37.4180951010362, 'lng': -122.098531723022, 'address': '', 'serial': 'Q2HP-F5K5-F98Q', 'mac': '88:15:44:ea:f5:bf', 'lanIp': '10.10.10.15', 'url': 'https://n149.meraki.com/DevNetSandbox/n/EFZDavc/manage/nodes/new_list/78214561218351', 'model': 'MS220-8P', 'switchProfileId': None, 'firmware': 'switch-11-31', 'floorPlanId': None} Refer to the exhibit. A developer needs to find the geographical coordinates of a device on the network L_397561557481105433 using a Python script to query the Meraki API. After running response = requests.get() against the Meraki API, the value of response.text is shown in the exhibit. What Python code is needed to retrieve the longitude and latitude coordinates of the device?
Answer options
A: latitude = response.text['lat'] longitude = response.text['lng']
B: latitude = response.json()['lat'] longitude = response.json()['lng'] Correct answer
C: latitude = response.json()[0] longitude = response.json()[1]
D: latitude = response.text[0] longitude = response.text[1]
Correct Answer:
B. latitude = response.json()['lat'] longitude = response.json()['lng']
Explanation

The response.text attribute from the Python requests library contains the raw response body as a string. The exhibit shows this string is in JSON format. To work with this data as a structured object in Python, it must be deserialized or parsed. The requests library provides a built-in method, .json(), which parses the JSON string into a Python dictionary. After parsing, the values for latitude and longitude can be accessed using their corresponding keys, 'lat' and 'lng', with standard Python dictionary syntax: dictionary['key'].

Why Incorrect

A. response.text is a string. Attempting to access it with dictionary-style keys like ['lat'] will result in a TypeError because strings are not subscriptable with string keys.
C. The .json() method in this case returns a single dictionary, not a list (JSON array). Accessing it with numerical indices like [0] will cause a KeyError.
D. Accessing response.text with numerical indices like [0] would retrieve the first character of the raw string ({), not the value associated with a key.

References

1. Official Vendor Documentation (Cisco Meraki): The Meraki Dashboard API documentation for the "Get device" endpoint (GET /devices/{serial}) shows that the response body is a JSON object containing keys such as lat and lng. This confirms the data structure shown in the exhibit.

Source: Meraki Developer Hub

Dashboard API V1

"Get device". (developer.cisco.com/meraki/api-v1/#!get-device)

2. Official Vendor Documentation (Python requests library): The official documentation for the requests library explicitly describes the use of the .json() method for handling JSON responses. It states

"There’s also a built-in JSON decoder

in case you’re dealing with JSON data... r.json()".

Source: requests Documentation

Version 2.31.0

"JSON Response Content". (requests.readthedocs.io/en/latest/user/quickstart/#json-response-content)

3. University Courseware (University of Michigan): Course materials for "Python for Everybody" explain how to parse JSON data retrieved from a web service. The materials demonstrate that after fetching data

it must be loaded from a string (if not using a library helper like .json()) into a dictionary to be accessed by key.

University of Michigan

"Python for Everybody

" Course 4: Using Python to Access Web Data

Chapter 13: Web Services and XML. (www.py4e.com/html3/13-web)

Scroll to Top