Courseiva

CCNA Data Serialization Questions

67 questions · Data Serialization · All types, answers revealed

1
MCQmedium

An engineer needs to convert an existing YAML-formatted inventory file into JSON format using a Python script. Which workflow accomplishes this transformation?

A.Directly pass the YAML file object into json.load().
B.Rename the file extension from .yaml to .json.
C.Load YAML with yaml.safe_load() and serialize to JSON with json.dumps().
D.Use yaml.safe_dump() directly on the JSON output stream.
AnswerC

Correct. Parsing YAML into native Python objects allows them to be re-serialized into JSON.

Why this answer

To convert YAML to JSON, the engineer must read and parse the YAML file into a Python data structure using yaml.safe_load(), and then serialize that structure into a JSON string using json.dumps().

2
MCQhard

You are writing a Python automation tool that reads telemetry data from a Junos device. The data is received as a JSON string containing forward slashes escaped as '\/'. When you load this string using json.loads(), how does Python handle the escaped slashes?

A.The parser raises a ValueError because escaped slashes are invalid in JSON.
B.They remain as literal escaped sequences ('\/').
C.They are converted to backslashes ('\').
D.They are automatically converted to unescaped forward slashes ('/').
AnswerD

Correct. json.loads() decodes escaped forward slashes into standard slashes.

Why this answer

JSON allows forward slashes to be escaped as '\/' for embedding JSON inside HTML script tags. Python's json.loads() automatically unescapes '\/' into normal '/' characters in the resulting string.

3
MCQeasy

Which symbol represents the beginning of a single YAML document stream?

A.Three hashes (###)
B.Three slashes (///)
C.Three dashes (---)
D.Three dots (...)
AnswerC

Correct. Three dashes indicate the start of a YAML document.

Why this answer

YAML documents can optionally begin with a document start marker consisting of three dashes (---).

4
Multi-Selectmedium

Which TWO Python exceptions might be raised when attempting to parse a malformed JSON string using the standard 'json' module? (Choose two)

Select 2 answers
A.AttributeError
B.JSONDecodeError
C.KeyError
D.ScannerError
E.TypeError
AnswersB, E

Correct. JSONDecodeError is raised for invalid JSON structure.

Why this answer

json.loads() raises JSONDecodeError (which inherits from ValueError) when encountering invalid JSON syntax.

5
MCQmedium

An automation engineer wants to log structured data from a Junos device automation run. The Python script formats a dictionary into a JSON string and prints it. However, the engineer wants all keys sorted alphabetically to ensure consistent log diffing. Which parameter accomplishes this in json.dumps()?

A.keys_sort=True
B.alphabetize=True
C.sort_keys=True
D.order='alphabetical'
AnswerC

Correct. sort_keys=True ensures that dictionary keys are output in alphabetical order.

Why this answer

The sort_keys parameter in json.dumps() sorts the output of dictionaries by key alphabetically.

6
MCQhard

When writing a Python script to interact with a Junos device via PyEZ, you receive an object representing RPC output. You want to serialize a custom Python class instance containing device metadata into JSON, but calling json.dumps() raises a TypeError. What is the standard approach to resolve this?

A.Pass a custom serialization function to the 'default' parameter in json.dumps().
B.Use yaml.safe_dump() instead, which natively serializes all custom Python classes.
C.Convert the object into an XML string before calling json.dumps().
D.Modify the global sys.path variable to include the custom class definition.
AnswerA

Correct. The 'default' parameter accepts a function that is called for objects that can't otherwise be serialized.

Why this answer

The json module does not know how to serialize custom Python object instances by default. You must provide a custom serialization function and pass it to the 'default' parameter of json.dumps().

7
Multi-Selecthard

You are writing a Python script to convert a complex Juniper device inventory from YAML format into JSON format using PyYAML and the built-in json module. Which THREE considerations must you keep in mind regarding differences between YAML and JSON during this conversion? (Choose three)

Select 3 answers
A.YAML allows unquoted strings for most values, whereas JSON strictly requires double quotes for all string literals.
B.Comments present in the YAML file will be automatically discarded during conversion to JSON because JSON does not support comments.
C.YAML anchors and aliases will be automatically preserved as native references in the resulting JSON output.
D.YAML scalar keys that are integers or booleans will be converted to string keys in JSON, as JSON object keys must be strings.
E.JSON supports multi-document streams natively in a single file just like YAML.
AnswersA, B, D

YAML allows plain unquoted strings in many contexts, but JSON requires explicit double-quote wrapping.

Why this answer

JSON does not support comments, requires double quotes for strings/keys, and only permits string keys in objects, whereas YAML allows comments, optional quotes, and non-string keys.

8
MCQeasy

Which of the following primitive data types is NOT supported natively in JSON?

A.Undefined
B.Number
C.String
D.Null
AnswerA

Correct. 'undefined' is a JavaScript concept and is not supported in JSON (which uses 'null').

Why this answer

JSON does not support undefined, functions, or undefined date types natively. Among standard choices, undefined or complex numbers are absent.

9
MCQmedium

An automation scripter needs to load a YAML configuration file in Python. To prevent arbitrary code execution vulnerabilities associated with untrusted files, which function should always be called?

A.yaml.safe_load()
B.yaml.load()
C.yaml.secure_load()
D.yaml.restricted_load()
AnswerA

Correct. yaml.safe_load() restricts the loader to standard data types, mitigating security risks.

Why this answer

yaml.safe_load() restricts loading to simple Python types like scalars, lists, and dicts, preventing instantiation of arbitrary Python objects.

10
Multi-Selecteasy

Which TWO characters or sequences are valid in YAML for representing lists or sequences? (Choose two)

Select 2 answers
A.Hyphen followed by a space (- )
B.Semicolon followed by a space (; )
C.Angle brackets (< >)
D.Curly braces ({ })
E.Square brackets ([ ])
AnswersA, E

Correct. Block sequences use hyphens.

Why this answer

YAML sequences can be represented using block style with hyphens (-) or flow style with square brackets ([]).

11
MCQmedium

An automation engineer writes a Python script that reads a Junos configuration file serialized in JSON. The file opens successfully, but parsing fails with a JSONDecodeError due to trailing commas at the end of object lists. How does standard JSON handle trailing commas compared to YAML?

A.JSON strictly forbids trailing commas, whereas YAML permits them in collections.
B.Both formats handle trailing commas identically by ignoring them.
C.JSON allows trailing commas, but YAML strictly forbids them.
D.Both JSON and YAML strictly require trailing commas for every key.
AnswerA

Correct. JSON syntax rules do not allow trailing commas, while YAML parsers accommodate them.

Why this answer

Standard JSON strictly prohibits trailing commas in objects and arrays, whereas YAML is much more lenient and allows trailing commas in sequences and mappings.

12
MCQhard

When converting a deeply nested JSON data structure representing Junos device health metrics into YAML using PyYAML, the output uses complex block styles that are difficult for team members to read. Which parameter in yaml.safe_dump() can force scalar values or containers to prefer flow style (JSON-like curly braces and brackets) instead?

A.force_json=True
B.format='compact'
C.style='flow'
D.default_flow_style=True
AnswerD

Correct. default_flow_style=True forces PyYAML to serialize collections in flow style (JSON-like syntax).

Why this answer

The default_flow_style parameter in yaml.safe_dump() controls how collections are dumped. Setting default_flow_style=False uses block style, while True or None dictates flow style formatting.

13
MCQeasy

An automation engineer is writing a Python script to parse a Juniper Junos NETCONF reply received in XML format and needs to convert it into a JSON structure for easier manipulation in a web application. Which built-in Python module is primarily used to handle JSON data serialization and deserialization?

A.json
B.pickle
C.yaml
D.xml.etree
AnswerA

The json module provides methods like dump(), dumps(), load(), and loads() for handling JSON data.

Why this answer

The 'json' module is the standard built-in Python library used for parsing, serializing, and deserializing JSON data.

14
MCQhard

You are writing a Python script that parses a multi-document YAML stream containing Junos device site configurations. One of the documents contains a custom YAML tag. When parsing with yaml.safe_load_all(), how does the safe loader handle custom tags?

A.It converts the tagged object into a JSON equivalent.
B.It automatically evaluates the custom tag using Python eval().
C.It raises a ConstructorError unless a custom constructor is registered.
D.It ignores the tag and loads the scalar value as a plain string.
AnswerC

Correct. Unknown tags in safe load mode trigger a ConstructorError.

Why this answer

The safe loader in PyYAML does not know how to construct objects from custom tags by default and will raise a ConstructorError unless a custom constructor has been explicitly registered.

15
MCQmedium

An automation script reads interface names and VLAN IDs from a CSV file and converts each row into a JSON object before sending it to a Junos device REST API. Which Python module is specifically designed to parse CSV (Comma-Separated Values) files?

A.yaml
B.json
C.xml
D.csv
AnswerD

Correct. The csv module handles parsing and generating CSV formatted tabular data.

Why this answer

The Python standard library includes the 'csv' module, which provides reader and writer objects for tabular CSV data.

16
MCQhard

You are writing a Python automation script that reads a Junos configuration file in JSON format. The JSON file contains duplicate keys within the same object scope. According to the JSON specification RFC 8259, how should a conforming JSON parser handle duplicate keys?

A.Behavior is undefined by the specification; typically the last defined key-value pair overwrites previous ones in Python dictionaries.
B.Both values are automatically combined into a JSON array under that key.
C.Duplicate keys are prohibited, and compliance checks will reject the file pre-parsing.
D.The parser must raise a fatal JSONDecodeError immediately.
AnswerA

Correct. Standard JSON parsers overwrite earlier keys with later ones when duplicates occur.

Why this answer

RFC 8259 states that while names within an object SHOULD be unique, the specification does not mandate how parsers should handle duplicates, resulting in behavior dependent on the parser (typically keeping the last encountered key-value pair).

17
MCQmedium

An engineer receives a YAML configuration snippet for a PyEZ automation script, but the script fails with a parser error. Upon inspection, the error is caused by improper indentation levels. Which rule must be strictly followed regarding indentation in YAML syntax?

A.Indentation is completely optional if curly braces are used.
B.Tabs must be used consistently for every level of indentation.
C.Indentation must always be exactly four spaces per level.
D.Spaces must be used for indentation, and tabs are strictly forbidden.
AnswerD

YAML relies on a fixed indentation space count and prohibits tabs to prevent indentation ambiguity.

Why this answer

YAML requires the use of space characters for indentation. Tab characters are strictly forbidden for indentation purposes.

18
MCQmedium

An automation engineer needs to convert a JSON payload representing Junos interface configurations into equivalent YAML format to reuse in an Ansible playbook. Which fundamental structural relationship between JSON and YAML makes this conversion straightforward?

A.JSON uses indentation for structure just like YAML.
B.JSON and YAML both strictly require curly braces for all data containers.
C.YAML is a strict superset of JSON, allowing valid JSON to be parsed as YAML.
D.YAML forces all numeric values to be encapsulated in strings.
AnswerC

Correct. Because YAML includes JSON as a subset, JSON structures can be seamlessly interpreted by YAML parsers.

Why this answer

YAML is a superset of JSON, meaning any valid JSON document is technically also a valid YAML document, allowing direct mapping of data structures.

19
Multi-Selectmedium

An automation engineer is reviewing data serialization formats used within Junos automation workflows. Which TWO statements are correct regarding JSON syntax and data types? (Choose two)

Select 2 answers
A.Single quotes can be used interchangeably with double quotes for strings.
B.JSON supports inline comments starting with the '#' symbol.
C.JSON object keys must be enclosed in double quotes.
D.The 'null' keyword is a valid data type in JSON.
E.Trailing commas are permitted in both arrays and objects.
AnswersC, D

Standard JSON specification requires all keys in an object to be strings enclosed in double quotation marks.

Why this answer

JSON object keys must always be double-quoted strings, and null is a valid scalar value representing an empty or missing value.

20
MCQmedium

During script development, an engineer encounters a YAML file containing comments and multiple configuration documents separated by document markers. Which characters are used to denote the start of a new document within a single YAML file stream?

A.===
B.---
C....
D.###
AnswerB

Three hyphens denote the document start marker in multi-document YAML files.

Why this answer

In YAML, three dashes (---) indicate the start of a document, while three dots (...) indicate the end of a document.

21
MCQmedium

A Python script retrieves interface statistics from a Junos device in JSON format, modifies a threshold value, and needs to output it back into a formatted JSON string with an indentation level of 4 spaces for readability. Which Python snippet achieves this?

A.json.format(data, spacing=4)
B.json.dumps(data, indent=4)
C.json.dump(data, indent=4)
D.json.stringify(data, spaces=4)
AnswerB

Correct. json.dumps() serializes a Python object to a JSON formatted string using an indentation of 4 spaces.

Why this answer

The json.dumps() method accepts an 'indent' parameter which specifies the number of spaces to use for pretty-printing the resulting JSON string.

22
MCQmedium

An automation engineer needs to pretty-print a JSON payload in the Linux terminal for debugging Junos telemetry. Which built-in Python command-line utility can be invoked to validate and pretty-print a JSON file?

A.python3 -m yaml.format filename.json
B.python3 -c 'import json; json.format()'
C.python3 -m json.tool filename.json
D.netconf-console --pretty filename.json
AnswerC

Correct. python3 -m json.tool validates and pretty-prints JSON files.

Why this answer

Python provides a command-line JSON tool via the json.tool module, invoked as 'python3 -m json.tool filename.json'.

23
MCQmedium

An automation engineer wants to verify the syntax of a large YAML playbook before executing it against a production Junos device. Which python one-liner command can be run in the terminal to quickly check if the file is syntactically valid YAML?

A.python3 -c 'import yaml, sys; yaml.safe_load(open(sys.argv[1]))' config.yaml
B.yaml --validate config.yaml
C.netconf-console --check config.yaml
D.python3 -m json.tool config.yaml
AnswerA

Correct. This command reads the file using PyYAML's safe_load, exiting with an error if syntax is invalid.

Why this answer

Running python3 -c 'import yaml, sys; yaml.safe_load(open(sys.argv[1]))' filename.yaml attempts to parse the file and will report any syntax errors.

24
MCQhard

A Python automation script extracts routing table entries from a Junos device. The data structure contains deeply nested dictionaries and lists. The engineer needs to perform a deep copy of this deserialized JSON structure before modifying it. Which Python module provides the deepcopy function needed to duplicate nested containers safely?

A.os
B.copy
C.sys
D.json
AnswerB

Correct. The copy module provides deepcopy() for duplicating complex nested data structures.

Why this answer

The 'copy' module in the Python standard library provides the deepcopy() function, which recursively clones nested dictionaries and lists.

25
MCQmedium

A network automation script is reading a YAML configuration file containing Junos device credentials. The script encounters an unhandled exception when attempting to load the file using PyYAML. Upon inspection, the error is caused by a tab character used for indentation instead of spaces. Which YAML specification rule does this violate?

A.Tab characters are strictly forbidden for indentation in YAML.
B.Comments must start with a double forward slash (//).
C.YAML files require all keys to be wrapped in double quotes.
D.Top-level keys must start with a hyphen (-) character.
AnswerA

Correct. YAML parsers throw a scanner error when tab characters are used for block indentation.

Why this answer

YAML 1.2 specifications explicitly prohibit the use of the tab character for indentation. All indentation whitespace must consist exclusively of space characters to maintain hierarchy definition.

26
Multi-Selecteasy

Which TWO of the following are valid scalar values in a YAML document? (Choose two)

Select 2 answers
A.Mapping
B.Integer
C.Sequence
D.String
E.Block
AnswersB, D

Correct. Integers are valid scalar values.

Why this answer

Scalars in YAML represent single values like strings and integers.

27
MCQeasy

Which of the following valid JSON values represents a boolean true state?

A.True
B."true"
C.TRUE
D.true
AnswerD

Correct. JSON booleans are strictly lowercase 'true'.

Why this answer

JSON booleans are lowercase words: true and false.

28
MCQeasy

An automation developer is examining a JSON response payload returned by a Juniper device via a REST API call. Which valid JSON data type is used to represent an ordered list of values enclosed within square brackets?

A.String
B.Array
C.Object
D.Boolean
AnswerB

JSON arrays represent ordered sequences of values enclosed in square brackets.

Why this answer

In JSON, arrays are ordered lists of values enclosed in square brackets ([...]).

29
MCQhard

An automation script reads a multi-document YAML file containing configuration templates for various Junos router models. To process each document individually in Python using PyYAML, which function should the engineer invoke?

A.yaml.read_multi()
B.yaml.load_all()
C.yaml.safe_load_all()
D.yaml.parse_documents()
AnswerC

Correct. yaml.safe_load_all() safely parses a multi-document YAML stream into an iterator of Python objects.

Why this answer

yaml.safe_load_all() is designed to parse a stream containing multiple YAML documents separated by '---', returning a generator that yields each parsed document sequentially.

30
MCQeasy

Which file extension is conventionally used for YAML data serialization files?

A..json
B..yaml
C..ini
D..xml
AnswerB

Correct. .yaml (or .yml) is the standard extension for YAML files.

Why this answer

YAML files typically use .yaml or .yml extensions.

31
MCQhard

A Python script reads a Junos configuration snippet stored in YAML. The configuration uses YAML anchors and aliases to duplicate common routing policy definitions across multiple VRFs. When the script parses the file using yaml.safe_load(), what happens to the anchors and aliases?

A.The parser raises a ScannerError because anchors are prohibited in safe mode.
B.The parser resolves the anchors and populates the resulting Python dictionary with the referenced data.
C.The aliases are ignored, resulting in empty values for those configuration blocks.
D.The parser treats the anchor syntax as literal string data.
AnswerB

Correct. yaml.safe_load() resolves anchors and aliases automatically during parsing.

Why this answer

yaml.safe_load() fully supports YAML anchors (&) and aliases (*) by default, dereferencing them into identical Python data structures in memory.

32
MCQeasy

Which of the following characters is used to start a comment line in a YAML document?

A.Exclamation mark (!)
B.Percent sign (%)
C.Double forward slash (//)
D.Hash sign (#)
AnswerD

Correct. The hash sign (#) designates a comment in YAML.

Why this answer

Comments in YAML begin with the hash or pound sign (#) and continue to the end of the line.

33
MCQmedium

An automation engineer is writing a script that saves operational telemetry data gathered from a Junos router. The data needs to be written directly to an open file stream in JSON format. Which method from the Python 'json' module should be used?

A.json.dumps()
B.json.to_file()
C.json.dump()
D.json.write()
AnswerC

Correct. json.dump() serializes a Python object directly to a file-like stream.

Why this answer

json.dump() takes a Python object and writes it directly to a file-like stream object, whereas json.dumps() returns a string.

34
MCQeasy

An engineer needs to represent an ordered list of IP addresses in a YAML configuration file for a Junos automation playbook. Which valid YAML syntax correctly defines a sequence of items?

A.ip_addresses = {192.168.1.1, 192.168.1.2}
B.ip_addresses: [192.168.1.1: 192.168.1.2]
C.ip_addresses: - 192.168.1.1 - 192.168.1.2
D.ip_addresses: * 192.168.1.1 * 192.168.1.2
AnswerC

Correct. The hyphen (-) prefix defines a list/sequence in YAML.

Why this answer

In YAML, lists or sequences are represented using a hyphen followed by a space (-) at the beginning of each line.

35
MCQhard

You are writing a Python automation script that processes JSON output from a Junos device's 'show interfaces' operational command via PyEZ. One of the interface descriptions contains raw control characters. When the script attempts to dump this data to a JSON string using json.dumps(), it raises a ValueError. Which parameter should you pass to json.dumps() to handle non-printable or out-of-range character encoding gracefully?

A.skipkeys=True
B.check_circular=False
C.ensure_ascii=False
D.allow_nan=True
AnswerC

Correct. ensure_ascii=False ensures that non-ASCII or special characters are serialized without crashing the encoder.

Why this answer

The json.dumps() function in Python includes an 'ensure_ascii' parameter. When set to False, it allows non-ASCII characters to be emitted directly without raising serialization errors or escaping them into Unicode escape sequences.

36
MCQeasy

Which Python function deserializes a JSON-formatted string into a native Python dictionary?

A.json.load()
B.json.read()
C.json.loads()
D.json.parse()
AnswerC

Correct. json.loads() parses a JSON string into Python data structures.

Why this answer

json.loads() (load string) is used to parse a JSON string into a Python object.

37
MCQmedium

An automation engineer is writing a Python script that takes a complex nested Python dictionary containing Junos telemetry parameters and converts it into a YAML string. Which PyYAML function should be used?

A.yaml.export()
B.yaml.serialize_string()
C.yaml.to_yaml()
D.yaml.safe_dump()
AnswerD

Correct. yaml.safe_dump() serializes a Python object into a safe YAML representation.

Why this answer

yaml.safe_dump() converts a Python object into a YAML-formatted string safely, avoiding the security risks associated with the base yaml.dump().

38
Multi-Selectmedium

Which TWO features are supported by YAML but are notably absent in standard JSON? (Choose two)

Select 2 answers
A.Native browser execution support without parsing libraries.
B.Strict enforcement of double quotes on all string keys.
C.Strict indentation-based block scoping.
D.Anchors and aliases for data reuse within the document.
E.Native support for comments using the hash (#) symbol.
AnswersD, E

Correct. YAML supports anchors (&) and aliases (*) for DRY data structures.

Why this answer

YAML supports comments and anchors/aliases, whereas standard JSON supports neither.

39
Multi-Selecthard

When serializing complex nested Python dictionaries to JSON, which THREE data types will cause a TypeError unless handled by a custom default encoder function? (Choose three)

Select 3 answers
A.Standard string objects
B.Python set objects
C.Custom class instances
D.Boolean values
E.Complex numbers
AnswersB, C, E

Correct. Sets are not JSON serializable by default.

Why this answer

Standard json.dumps() cannot serialize sets, complex numbers, or custom class instances without custom encoder logic.

40
Multi-Selecthard

When writing an automation script that converts data formats between YAML and JSON for Junos configuration pipelines, which THREE potential pitfalls should an engineer account for? (Choose three)

Select 3 answers
A.YAML automatically guarantees lossless round-trip conversion for all Python objects.
B.JSON files natively support YAML anchors and aliases.
C.JSON integer keys are automatically converted to strings in Python dictionaries.
D.YAML comments are entirely lost when converting a YAML document to JSON.
E.Certain unquoted YAML scalars (like 'yes' or leading-zero numbers) may change type during parsing.
AnswersC, D, E

Correct. JSON specification requires all object keys to be strings.

Why this answer

Data type coercion differences (like booleans/octals), lack of comment preservation in JSON, and duplicate key behaviors are common conversion hurdles.

41
MCQmedium

An automation script reads a configuration template where boolean values are represented as 'yes' and 'no' in YAML. When parsed using PyYAML in Python, how are these values interpreted?

A.They are converted to integer 1 and 0 values.
B.They are interpreted as Python boolean True and False values.
C.They remain as literal string objects ('yes' and 'no').
D.The parser raises a ConstructorError because only 'true' and 'false' are valid.
AnswerB

Correct. PyYAML automatically converts 'yes' and 'no' into native boolean types.

Why this answer

In YAML 1.1 (which PyYAML predominantly implements), unquoted words like 'yes', 'no', 'true', 'false', 'on', and 'off' are automatically parsed into native boolean values.

42
Multi-Selecthard

When serializing Python data structures to JSON for Junos automation payloads, which THREE parameters can be passed to json.dumps() to control formatting and readability? (Choose three)

Select 3 answers
A.max_depth
B.separators
C.sort_keys
D.strict_mode
E.indent
AnswersB, C, E

Correct. separators allows customizing item and key-value token dividers (e.g., removing whitespace).

Why this answer

Parameters like indent, sort_keys, and separators are standard formatting arguments for json.dumps().

43
MCQmedium

An automation engineer needs to include comments explaining complex network parameters inside a Junos automation data file. Which serialization format should the engineer select?

A.CSV
B.YAML
C.JSON
D.Pickle
AnswerB

Correct. YAML supports inline and block comments using the hash (#) symbol.

Why this answer

YAML natively supports comments using the hash (#) symbol, whereas standard JSON does not support comments.

44
MCQhard

You are writing a Python script using the PyEZ library to retrieve interface facts from a Juniper EX Series switch. The resulting data structure is stored in a Python dictionary. You need to dump this dictionary into a YAML file so it can be read by an Ansible playbook later. Which PyYAML function should you use to convert the Python dictionary into a YAML-formatted string or file stream?

A.yaml.load()
B.yaml.serialize()
C.yaml.safe_load()
D.yaml.dump()
AnswerD

yaml.dump() serializes a Python object structure into a YAML byte or string stream.

Why this answer

yaml.dump() is the standard PyYAML function used to serialize Python objects (such as dictionaries) into a YAML-formatted stream or string.

45
MCQeasy

What is the native data format returned by Junos devices when queried via REST API or NETCONF operations configured with JSON output formatting?

A.INI
B.YAML
C.CSV
D.JSON
AnswerD

Correct. Queries configured for JSON return JSON-formatted payloads.

Why this answer

When JSON output is requested from Junos REST or NETCONF, the returned data is serialized in JSON format.

46
Multi-Selecthard

When working with PyYAML in Python for Junos automation scripts, which THREE of the following practices enhance script security and robustness? (Choose three)

Select 3 answers
A.Always using yaml.safe_load() instead of yaml.load() to prevent arbitrary code execution.
B.Catching yaml.scanner.YAMLError exceptions to handle malformed configuration syntax gracefully.
C.Storing unencrypted credentials directly inside YAML global anchors.
D.Relying on yaml.load() to automatically execute embedded Python object constructors.
E.Using yaml.safe_dump() when generating output configurations for consistency.
AnswersA, B, E

Correct. yaml.safe_load() mitigates security vulnerabilities by restricting deserialization.

Why this answer

Using safe loading methods, verifying file existence, and handling scanner errors properly are best practices when processing external YAML configurations.

47
MCQmedium

An automation engineer is writing a Python script to push configurations to a Junos device. The script loads a YAML data file containing interface descriptions. One description contains a colon without a following space (e.g., 'Interface:Primary'). What error will PyYAML raise when attempting to parse this file?

A.TypeError
B.ScannerError
C.YAMLSemanticError
D.JSONDecodeError
AnswerB

Correct. Missing whitespace after a colon violates YAML mapping rules, resulting in a ScannerError.

Why this answer

In YAML, a colon must be followed by a whitespace character to be recognized as a mapping key-value separator. If no space follows, PyYAML raises a ScannerError or MappingValuesError.

48
MCQhard

An automation script needs to convert a JSON string containing Juniper interface statistics into a YAML format to maintain consistency with existing Ansible variable files. When performing this conversion, which structural capability does YAML support that standard JSON does not?

A.Support for comments
B.Support for numeric floating-point values
C.Support for boolean data types
D.Support for nested arrays
AnswerA

YAML supports inline comments using the '#' character, whereas JSON does not support comments.

Why this answer

YAML natively supports complex keys (such as using objects or tuples as keys) and comments, whereas standard JSON requires all keys to be strings and does not support comments.

49
Multi-Selecteasy

Which TWO of the following are valid primitive data types in JSON? (Choose two)

Select 2 answers
A.String
B.Function
C.Boolean
D.Undefined
E.Symbol
AnswersA, C

Correct. Strings are a fundamental primitive type in JSON.

Why this answer

JSON primitive types include strings, numbers, booleans, and null. Arrays and objects are composite types.

50
MCQeasy

What is the primary delimiter used to separate key-value pairs in a JSON object?

A.Comma (,)
B.Forward slash (/)
C.Semicolon (;)
D.Period (.)
AnswerA

Correct. Commas separate elements within JSON objects and arrays.

Why this answer

JSON object key-value pairs are separated by commas (,).

51
MCQhard

A Python script processes a YAML configuration template for Junos BGP neighbors. The configuration contains a multi-line banner string description. Which YAML block scalar indicator preserves newlines exactly as written in the text block?

A.The pipe symbol (|)
B.The ampersand symbol (&)
C.The greater-than symbol (>)
D.The asterisk symbol (*)
AnswerA

Correct. The literal style indicator (|) preserves newlines in multi-line strings.

Why this answer

In YAML, the pipe symbol (|) denotes a literal scalar style, which preserves newlines within multi-line strings.

52
MCQhard

You are writing a Python automation script that processes configuration data. The script reads a YAML file containing Junos firewall filters, modifies them, and writes them back out. However, you notice that all the original comments in the file are stripped out in the output. What is the fundamental reason for this behavior in standard PyYAML dump operations?

A.The yaml.safe_dump() function explicitly deletes comments for security reasons.
B.Comments are stripped during parsing because they are not part of the YAML data model.
C.YAML specification mandates that all comments are ephemeral and cannot be serialized.
D.Comments must be re-injected using the 'preserve_comments=True' parameter.
AnswerB

Correct. Parsers drop comments since data structures only contain keys, values, and sequence items.

Why this answer

PyYAML parses YAML files into abstract syntax trees (AST) or Python native data structures, discarding comments during the parsing phase because comments are not part of the data model.

53
MCQeasy

What type of brackets enclose an array in a JSON document?

A.Curly braces ({ })
B.Square brackets ([ ])
C.Angle brackets (< >)
D.Parentheses (( ))
AnswerB

Correct. Square brackets denote arrays in JSON.

Why this answer

Arrays in JSON are enclosed within square brackets ([ and ]).

54
MCQeasy

An automation engineer is writing a Python script to parse a Juniper Junos NETCONF reply received in XML format and needs to convert it into a native Python dictionary for internal processing. Which built-in library should the engineer use to convert the structured XML tree?

A.xml.etree.ElementTree
B.pickle
C.yaml
D.json
AnswerA

Correct. xml.etree.ElementTree provides functions to parse XML strings and files into hierarchical tree structures.

Why this answer

xml.etree.ElementTree is a standard Python library used for parsing and navigating XML data structures. While JSON and YAML are common serialization formats, NETCONF protocol responses natively return XML, which must be parsed before data manipulation.

55
MCQeasy

Which of the following describes the fundamental structural difference between JSON and YAML regarding syntax design?

A.YAML requires all keys to be enclosed in double quotes, whereas JSON does not.
B.YAML does not support lists or arrays.
C.JSON relies on explicit punctuation like braces and brackets, whereas YAML relies heavily on indentation.
D.JSON supports comments natively, whereas YAML does not.
AnswerC

Correct. JSON uses structural syntax tokens, while YAML uses indentation.

Why this answer

JSON relies explicitly on structural characters (curly braces, brackets, quotes, commas) to define hierarchies, whereas YAML primarily relies on indentation and whitespace.

56
MCQmedium

An engineer writes a Python script that loads a JSON configuration file using the json.load() method. The file contains configuration parameters for a Junos device. If the JSON file contains a trailing comma at the end of the last element in an array, what will happen when the script executes?

A.The script will successfully parse the file and ignore the trailing comma.
B.The script will raise a JSONDecodeError.
C.The script will throw a TypeError during execution.
D.The script will convert the trailing comma into a null value automatically.
AnswerB

Trailing commas violate standard JSON syntax rules, causing the parser to fail with a decode error.

Why this answer

Standard JSON specification is strict and does not allow trailing commas. Attempting to parse it will raise a json.decoder.JSONDecodeError.

57
MCQhard

You are writing a Python script that converts a Junos operational state output from XML (via NETCONF) into JSON. The XML structure contains sibling elements with the same tag name. When converted naively, how do standard XML-to-JSON conversion libraries (like xmltodict) typically represent these repeated sibling elements in the resulting JSON dictionary?

A.By appending numeric indexes to every key name automatically.
B.As a JSON array containing multiple objects.
C.By raising a DuplicateElementException.
D.By overwriting previous elements so only the last element is retained.
AnswerB

Correct. Sibling elements with identical tags are aggregated into a JSON array.

Why this answer

Conversion libraries like xmltodict represent repeated sibling XML elements as a JSON array (list) to preserve all instances under a single key.

58
Multi-Selectmedium

Which TWO methods are provided by the Python standard library 'json' module for deserializing JSON data? (Choose two)

Select 2 answers
A.json.read()
B.json.decode()
C.json.loads()
D.json.load()
E.json.parse()
AnswersC, D

Correct. json.loads() deserializes JSON from a string.

Why this answer

The json module provides json.load() for file-like objects and json.loads() for strings.

59
MCQhard

When parsing a Junos configuration snippet in YAML, an engineer notices a string value starting with a zero (e.g., '01234') that is unquoted. How do YAML parsers typically interpret this value?

A.The parser throws a ScannerError due to invalid numeric formatting.
B.As a string literal matching the exact characters.
C.As a floating-point number with zero prefix.
D.As an octal integer.
AnswerD

Correct. Leading zeros in YAML 1.1 trigger octal integer interpretation.

Why this answer

In YAML 1.1, numbers starting with a leading zero are interpreted as octal (base 8) integers. To ensure it is treated as a string, it must be quoted.

60
MCQeasy

Which character is used to indicate a mapping key-value pair in YAML syntax?

A.Semicolon (;)
B.Arrow (->)
C.Colon (:)
D.Equals sign (=)
AnswerC

Correct. A colon separates keys and values in YAML mapping pairs.

Why this answer

In YAML, a key-value mapping is represented by a colon followed by a space (: ).

61
Multi-Selectmedium

Which TWO Python standard library modules are commonly combined when a script needs to fetch web content (such as Junos REST API data) and parse the resulting payload? (Choose two)

Select 2 answers
A.json
B.yaml
C.socket
D.urllib.request
E.pickle
AnswersA, D

Correct. json is required to parse API responses.

Why this answer

The 'urllib.request' module handles HTTP requests, and the 'json' module handles parsing the resulting JSON response.

62
Multi-Selecteasy

An automation developer is designing a script that reads routing policy parameters from a configuration file. Which TWO data formats are natively supported and commonly used across Junos automation toolchains like PyEZ, Ansible, and REST APIs for data serialization? (Choose two)

Select 2 answers
A.YAML
B.BMP
C.JSON
D.RTF
E.EXE
AnswersA, C

YAML is extensively used for playbooks, variable definitions, and configuration templates in tools like Ansible and PyEZ.

Why this answer

JSON and YAML are the primary lightweight data serialization formats universally utilized across modern network automation toolchains and APIs.

63
MCQhard

A Python automation script parses a Junos telemetry stream in JSON. The JSON payload uses integer keys in a dictionary (e.g., {443: 'HTTPS'}). When loaded into Python using json.loads(), what data type do the dictionary keys become?

A.They are converted to floating-point numbers.
B.They remain integer objects.
C.The parser raises a KeyError because JSON keys must be alphabetic.
D.They are converted to Python string objects.
AnswerD

Correct. JSON keys are strictly strings, so json.loads() converts them to string keys in Python.

Why this answer

JSON specification dictates that object keys must be strings. When json.loads() parses an object, any keys (even if numeric-looking) are converted to Python strings.

64
MCQeasy

Which of the following data types is natively supported in JSON without requiring custom serialization handlers?

A.Python set
B.Complex number
C.Python tuple
D.Boolean
AnswerD

Correct. Boolean values (true and false) are natively supported primitive types in JSON.

Why this answer

JSON natively supports strings, numbers, booleans, null, arrays, and objects (dictionaries with string keys). Python tuples or sets are not natively supported.

65
MCQhard

A Python script receives a JSON payload from a Junos device containing 64-bit interface counter integers. When loaded using the standard 'json' module, the script experiences precision loss on counter values exceeding standard integer limits. Which alternative JSON parser package for Python should be used to handle high-precision integers without data degradation?

A.simplejson with use_decimal=True
B.corejson
C.xmljson
D.fastjson
AnswerA

Correct. simplejson supports parsing numbers into Python Decimal objects to prevent precision loss.

Why this answer

The 'ujson' (UltraJSON) or 'simplejson' libraries provide options like parse_float or parse_int to handle high-precision numbers. Specifically, simplejson supports a 'use_decimal=True' parameter to decode JSON numbers into Python Decimal objects.

66
Multi-Selecteasy

Which TWO of the following are valid extensions commonly used for YAML files? (Choose two)

Select 2 answers
A..xml
B..jsn
C..yaml
D..txt
E..yml
AnswersC, E

Correct. .yaml is a standard extension for YAML.

Why this answer

YAML files commonly use either .yaml or .yml file extensions.

67
MCQeasy

Which Python module is part of the standard library and provides functions to serialize and deserialize JSON data?

A.requests
B.yaml
C.junos-eznc
D.json
AnswerD

Correct. The json module is built into the Python standard library.

Why this answer

The 'json' module is part of the Python standard library and requires no external installation.

Ready to test yourself?

Try a timed practice session using only Data Serialization questions.