Automation and Programmability

A JSON document is {"interfaces":[{"name":"Gi0/1","enabled":true,"ips":["10.0.0.1","10.0.1.1"]}]}. Which path, using dot and zero-based index notation, returns 10.0.1.1?

Show the answer

Correct answerC. interfaces[0].ips[1]

AWhy not this: Index 1 in interfaces does not exist, because the array has only one object at index 0.

BWhy not this: Skips the array index; interfaces is an array, so an element must be chosen before reading ips.

CWhy this is right: Selects the first object in the interfaces array, then the second element of its ips array, which is 10.0.1.1.

DWhy not this: Assumes indexes start at 1; ips has only indexes 0 and 1, so index 2 is out of range.

The interfaces value is an array holding one object at index 0, and that object's ips key holds an array whose second element is index 1. Counting from one, as in interfaces[0].ips[2], points past the end of the two-element list.