300-435 Question 41
Single answerYou are using Cisco's YANG Suite to validate a JSON instance document against a YANG model for a network configuration. The YANG model specifies the following structure:
module example-config {
namespace "http://cisco.com/example-config";
prefix ec;
container network {
leaf hostname {
type string;
}
leaf ip-address {
type string;
}
}
}
Which of the following JSON instances correctly conforms to the YANG model?
- A
{ "network": { "hostname": "router1", "ip-address": "192.168.1.1" } }
- B
{ "example-config": { "hostname": "router1", "ip-address": "192.168.1.1" } }
- C
{ "network": { "hostname": 12345, "ip-address": "192.168.1.1" } }
- D
{ "network": { "hostname": "router1" } }
Show answer and explanation
Correct answer: A
Explanation
To validate a JSON instance against a YANG model, the structure, field names, and data types in the JSON must match those defined in the YANG model. The correct JSON instance must include the 'network' container with both 'hostname' and 'ip-address' leaves, and their values must conform to the expected types (string in this case).
- A. Correct.
This JSON instance is correctly structured to match the YANG model. It includes the 'network' container and both required leaves ('hostname' and 'ip-address') with valid types (string).
- B. Incorrect.
This JSON instance uses an incorrect top-level container name ('example-config') instead of 'network', so it does not conform to the model.
- C. Incorrect.
This JSON instance contains an invalid type for the 'hostname' field. The YANG model requires it to be a string, but a number is provided.
- D. Incorrect.
This JSON instance is missing the required 'ip-address' field, which is defined as mandatory in the YANG model.