nerdexam
CiscoCisco

350-401 · Question #677

350-401 Question #677: Real Exam Question with Answer & Explanation

The correct answer is C: Append to the body of the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(Response.text). Option C is correct because the file-writing block must be appended inside (as part of the body of) the for loop so that a separate JSON file is created for each device using that device's hostname. Response.text already contains the raw JSON-formatted string returned by the HTTP

Submitted by salim_om· Mar 6, 2026Network Automation and Programmability - Writing Python scripts to interact with network device APIs and save structured data to files (e.g., Cisco DevNet / CCNP Enterprise automation objectives)

Question

Refer to the exhibit. How should the script be completed so that each device configuration is saved into a JSON-formatted file under the device name? A. B. C. D.

Options

  • AInsert after the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(Response)
  • BInsert after the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(json.dumps(Response.text))
  • CAppend to the body of the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(Response.text)
  • DInsert immediately before the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(json.load(Devices))

Explanation

Option C is correct because the file-writing block must be appended inside (as part of the body of) the for loop so that a separate JSON file is created for each device using that device's hostname. Response.text already contains the raw JSON-formatted string returned by the HTTP/REST API call, so writing it directly with OutFile.write() produces a valid JSON file without any additional serialization.

Topics

#Python scripting#REST API#JSON file handling#network automation

Community Discussion

No community discussion yet for this question.

Full 350-401 PracticeBrowse All 350-401 Questions