exam questions

Exam 350-401 All Questions

View all questions & answers for the 350-401 exam

Exam 350-401 topic 1 question 496 discussion

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

Which Python code snippet must be added to the script to store the changed interface configuration to a local JSON-formatted file?

A.

B.

C.

D.

Show Suggested Answer Hide Answer
Suggested Answer: B

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
iGlitch
Highly Voted 2 years, 2 months ago
B is correct because: 1 - 'response' type is (class Response). 2 - 'UpdateConfig' converted 'response' to a String, so it's a String. 3 - When using write() the passed argument must be a String. NOT C, json.dump(ARG1, ARG2) method takes a python dictionary NOT a String, and convert it as a JSON file. HTH
upvoted 10 times
...
matass_md
Most Recent 2 days, 11 hours ago
Answer is C . After some research about OutFile=open( "ifaces.json " , "w") w > stands for write access in the folder "ifaces.json" it could be any address type /user/home/MyFile it's just a location , the name they gave it is confusing . INTERFACES.JSON > ifaces.json we need to use json.dump(UpdatedConfig,OutFile) we make a JSON string that we save in the location of OutFile that we earlier told it where it could be. OutFile.close() closes the "folder" that we just open in the first line
upvoted 1 times
...
[Removed]
8 months, 1 week ago
B is correct 2001:db8:1: is updated to "2001:db8:cafe so we need to write the UpdatedConfig string to the file to store the updated interface configuration.
upvoted 2 times
...
slacker_at_work
1 year ago
In Python, JSON serialization is typically performed using the json.dump() or json.dumps() functions. json.dump() is used to serialize a Python object (such as a dictionary or a list) directly into a file-like object, while json.dumps() is used to serialize a Python object into a JSON string.
upvoted 2 times
...
slacker_at_work
1 year ago
It is Option B: B: This option writes the UpdatedConfig variable, which presumably contains the modified configuration, to the file. It directly writes the modified configuration to the file in its current string form. This option is simple and effective if UpdatedConfig contains the desired JSON-formatted configuration.
upvoted 2 times
...
slacker_at_work
1 year ago
import json import requests Creds = ("user", "Z#419010526SmnV") Headers = { "Content-Type": "application/yang-data+json", "Accept": "application/yang-data+json"} BaseURL = https://cpe/restconf/data" URL = BaseURL + "/Cisco-IOS-XE-native:native/interface" Response = requests.get(URL, auth= Creds, headers = Headers, verify=False) UpdatedConfig = Response.text.replace("2001:db8:1:", "2001:db8:cafe:") A: OutFile = open("ifaces.json", "w") OutFile.write(Response.text) OutFile.close() B: OutFile= open("ifaces.json", "w") OutFile.write(UpdatedConfig) OutFile.close() C: OutFile= open("ifaces.json", "w") json.dump(UpdatedConfig,OutFile) OutFile.close() D: OutFile = open("ifaces.json", "w") OutFile.write(Response.json()) OutFile.close()
upvoted 2 times
...
Chuckzero
1 year, 5 months ago
The correct answer is B. This question is testing your knowledge of the difference between json.dump() and json.dumps(). When you see json.dump() -> It is used for saving JSON-formatted data to a file. json.dumps() - Dumps the data to a memory for future use. You can call the json-formatted data later for use such as sending it over a network or embedding it to a web page.
upvoted 1 times
...
Zizu007
2 years, 3 months ago
B is correct. C is wrong: json.dump() expects python <dict> type as input. in this case "Response.text.replace()" is a <str> data type in Python.
upvoted 3 times
...
kuzma
2 years, 3 months ago
UpdatedConfig = Response.text bla-bla-bla -> type str type str not serialisible, so json.dump(UpdatedConfig, OutFile) - returns error Answer B, but it is no json-formatted file
upvoted 4 times
Lalane
2 years, 3 months ago
Correct answer is "C", json.dump (dump without s) allow you convert a text file to json format
upvoted 1 times
iGlitch
2 years, 2 months ago
You got it all wrong my g :(
upvoted 1 times
...
...
Zizu007
2 years, 3 months ago
B is correct. read the file again in python with json.load().
upvoted 1 times
...
...
doron1122
2 years, 4 months ago
Looks like its C https://pynative.com/python-json-dumps-and-dump-for-json-encoding/
upvoted 4 times
Clauster
1 year, 11 months ago
Thanks, the answer is def C
upvoted 1 times
...
...
Titini
2 years, 5 months ago
Why not C
upvoted 1 times
iGlitch
2 years, 2 months ago
Because: 1 - 'response' type is (class Response). 2 - 'UpdateConfig' converted 'response' to a String, so it's a String. 3 - When using write() the passed argument must be a String. NOT C, json.dump(ARG1, ARG2) method takes a python dictionary NOT a String, and convert it as a JSON file. HTH
upvoted 1 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