Courseiva
Data Serialization →mediumMultiple Choice

JNCIA-DevOps Practice Question: A Python script retrieves interface statistics from a Junos device in JSON format,…

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?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

json.dumps(data, indent=4)

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

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    json.format(data, spacing=4)

    Why it's wrong here

    No json.format function or spacing parameter exists in Python's json module; the call raises AttributeError. The module offers dumps with an indent argument, which is the correct choice when a formatted JSON string is required.

  • ✓

    json.dumps(data, indent=4)

    Why this is correct

    json.dumps() serialises a Python object into a JSON-formatted string, and its indent parameter inserts the specified number of spaces per nesting level. Passing indent=4 therefore produces the readable, four-space-indented JSON string the script requires, satisfying the formatting constraint in the stem.

  • ✗

    json.dump(data, indent=4)

    Why it's wrong here

    json.dump writes serialised JSON to a file-like object, so it returns None rather than a string, failing the requirement to output a formatted JSON string. It is the right call when writing directly to an open file handle instead of capturing the result.

  • ✗

    json.stringify(data, spaces=4)

    Why it's wrong here

    Python's json module has no stringify function, and no spaces parameter exists; this is JavaScript's JSON.stringify, which takes a space argument. It would be correct only in a Node.js or browser script, not a Python script manipulating Junos JSON output.

About these practice questions

This JNCIA-DevOps question is part of Courseiva's 273-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

You might also like

Similar JNCIA-DevOps questions

Written and reviewed by Johnson Ajibi, MSc IT Security

Security Systems Architect · founder of Courseiva

Last reviewed August 2026 · checked against the official Juniper Networks exam blueprint

This JNCIA-DevOps practice question is part of Courseiva's free Juniper Networks certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the JNCIA-DevOps exam.