nerdexam
Cisco

300-435 · Question #146

Refer to the exhibit. A network engineer must configure a loopback on all routers. To automate the procedure, a script is used. Which code snippet must be added to the box in the code to perform…

The correct answer is A. json.dumps(payload). When sending a Python dictionary as a JSON body in an HTTP request, it must first be serialized to a JSON-formatted string using json.dumps().

Network Automation Foundation

Question

Refer to the exhibit. A network engineer must configure a loopback on all routers. To automate the procedure, a script is used. Which code snippet must be added to the box in the code to perform this task?

Exhibit

300-435 question #146 exhibit

Options

  • Ajson.dumps(payload)
  • Bjson.loads(payload)
  • Cjson.dump(payload)
  • Djson.load(payload)

How the community answered

(29 responses)
  • A
    93% (27)
  • B
    3% (1)
  • D
    3% (1)

Why each option

When sending a Python dictionary as a JSON body in an HTTP request, it must first be serialized to a JSON-formatted string using json.dumps().

Ajson.dumps(payload)Correct

json.dumps() serializes a Python object (such as a dict) into a JSON string, which is required when passing data as the body of an HTTP request. Without this conversion, the requests library would send a raw Python dict representation instead of valid JSON. The other variants either read JSON rather than write it, or write to a file object rather than returning a string.

Bjson.loads(payload)

json.loads() deserializes a JSON string into a Python object - it reads JSON, it does not produce it for use in a request body.

Cjson.dump(payload)

json.dump() writes a Python object as JSON directly to a file-like object, not to a string variable usable as a request payload.

Djson.load(payload)

json.load() reads JSON from a file-like object and returns a Python object - it is the file-based counterpart to json.loads(), not a serializer.

Concept tested: Python json.dumps for HTTP request serialization

Source: https://docs.python.org/3/library/json.html

Topics

#Python json module#Data serialization#REST API#Network automation scripting

Community Discussion

No community discussion yet for this question.

Full 300-435 Practice