350-401 Question 314
Single answerYou are configuring a network automation script, and the script requires a valid JSON-encoded file to define the configuration of a Cisco router. Which of the following JSON file snippets is valid and properly formatted?
- A
{ 'hostname': 'Router1', 'interfaces': [ { 'name': 'GigabitEthernet0/0', 'ip': '192.168.1.1' } ] }
- B
{ "hostname": "Router1", "interfaces": [ { "name": "GigabitEthernet0/0", "ip": "192.168.1.1" } ] }
- C
{ "hostname": "Router1", "interfaces": { "name": "GigabitEthernet0/0", "ip": "192.168.1.1" } }
- D
{ "hostname": "Router1", "interfaces": [ { "name": "GigabitEthernet0/0", "ip": "192.168.1.1" }, ] }
Show answer and explanation
Correct answer: B
Explanation
Option 2 is the correct answer because it adheres to the JSON standard, including the use of double quotes for strings and proper structural formatting for objects and arrays. JSON syntax is strict, and common errors, such as the use of single quotes, trailing commas, or incorrect object structures, can cause a file to be invalid.
- A. Incorrect.
This option is invalid because JSON requires double quotes (") for strings, but this snippet uses single quotes (').
- B. Correct.
This option is valid because it uses proper JSON formatting: strings are enclosed in double quotes, and arrays and objects are correctly structured.
- C. Incorrect.
This option is invalid because the 'interfaces' key should use an array ([]) to list multiple objects, but it incorrectly uses an object ({}) instead.
- D. Incorrect.
This option is invalid because it includes a trailing comma (,) after the last item in the array, which is not allowed in JSON.