350-401 · Question #616
Which Python code snippet must be added to the script to save the returned configuration as a JSON-formatted file? A. B. C. D.
The correct answer is B. with open("ifaces.json", "w") as OutFile: OutFile.write(Response.text). Option B is correct because Response.text returns the raw string content of the HTTP response, which is already in JSON format (as text), and writing it directly to a file with 'w' mode saves it as a valid JSON-formatted file. The file is opened in write mode ('w') which is appro
Question
Which Python code snippet must be added to the script to save the returned configuration as a JSON-formatted file? A. B. C. D.
Exhibits
Options
- Awith open("ifaces.json", "w") as OutFile: OutFile.write(Response)
- Bwith open("ifaces.json", "w") as OutFile: OutFile.write(Response.text)
- Cwith open("ifaces.json", "w") as OutFile: JSONResponse = json.loads(Response.text) OutFile.write(JSONResponse)
- Dwith open("ifaces.json", "w") as OutFile: OutFile.write(Response.json())
How the community answered
(65 responses)- A3% (2)
- B75% (49)
- C8% (5)
- D14% (9)
Explanation
Option B is correct because Response.text returns the raw string content of the HTTP response, which is already in JSON format (as text), and writing it directly to a file with 'w' mode saves it as a valid JSON-formatted file. The file is opened in write mode ('w') which is appropriate, and Response.text preserves the JSON string exactly as received from the API.
Topics
Community Discussion
No community discussion yet for this question.

