Soru

Zorluk: ZorInterpreting JSON Encoded Data

A network engineer performs an HTTP GET request to a Cisco IOS XE RESTCONF interface configuration endpoint. The server returns the following JSON payload:

{
"ietf-interfaces:interfaces": {
"interface": [
{
"name": "GigabitEthernet0/0/0",
"type": "iana-if-type:ethernetCsmacd",
"enabled": "true",
"ietf-ip:ipv4": {
"address": [
{
"ip": "192.168.10.1",
"netmask": "255.255.255.0"
}
]
}
},
{
"name": "GigabitEthernet0/0/1",
"type": "iana-if-type:ethernetCsmacd",
"enabled": false,
"ietf-ip:ipv4": {
"address": [
{
"ip": "10.0.1.1",
"netmask": "255.255.255.252"
}
]
}
}
]
}
}

Which TWO statements accurately interpret the structure and data types in this JSON payload?

  1. The key path payload["ietf-interfaces:interfaces"]["interface"][0]["enabled"] evaluates to a String data type rather than a Boolean primitive.Cevap
  2. The path expression payload["ietf-interfaces:interfaces"]["interface"][1]["ietf-ip:ipv4"]["address"][0]["ip"] resolves to the IP address "10.0.1.1".Cevap
  3. C
    The element mapped to payload["ietf-interfaces:interfaces"]["interface"][0]["ietf-ip:ipv4"]["address"] is a JSON Object (dictionary).
  4. D
    The expression payload["ietf-interfaces:interfaces"]["interface"][0]["name"] extracts the interface name "GigabitEthernet0/0/1".

Cevap

The statement identifying the 'enabled' key in the first interface as a String data type and the path navigating to '10.0.1.1' using array index [1] and address index [0] are both correct.
The option noting that the 'enabled' key contains a String is correct because the value is enclosed in quotes ("true"). The option identifying the path to '10.0.1.1' is correct because index [1] accesses the second interface (GigabitEthernet0/0/1) in zero-indexed JSON array navigation.

Adım Adım Çözüm

1
Analyze data types for the 'enabled' key in GigabitEthernet0/0/0.
The value is wrapped in double quotes ("true"), signifying a string primitive in JSON syntax, unlike GigabitEthernet0/0/1 which uses an unquoted boolean literal (false).
Quotations differentiate string values from boolean keywords in JSON parsing.
2
Trace the array index and dictionary path to locate IP address '10.0.1.1'.
The root dictionary has key 'ietf-interfaces:interfaces' -> key 'interface' (list) -> index [1] (second element GigabitEthernet0/0/1) -> key 'ietf-ip:ipv4' (object) -> key 'address' (list) -> index [0] (first element) -> key 'ip' returns '10.0.1.1'.
JSON arrays start at index 0, so index 1 selects the second item in the list.
3
Evaluate the remaining choices against JSON syntax rules.
The 'address' key holds square brackets [], which denote a list/array, not a dictionary object {}. Index [0] on 'interface' yields GigabitEthernet0/0/0, not GigabitEthernet0/0/1.
Square brackets define ordered arrays and zero-indexing governs list positioning.

Anahtar Kavram

Interpreting JSON Encoded Data Types and Nested Structure Navigation
Tahmini Süre:2m 0s
Bu soruyu puanla