1. Home
  2. Data Science
  3. Python
  4. What does json.dumps(obj, indent=2) do in Python?

Added 25 Nov 2026

What does json.dumps(obj, indent=2) do in Python?

  1. Compresses JSON
  2. Encrypts JSON
  3. Sorts keys
  4. Pretty-prints JSON with 2-space indentation Correct answer

Correct answer

D. Pretty-prints JSON with 2-space indentation

MCQSEXAM

Explanation

The indent parameter formats output for readability.

Reference

Asked in: Python Interview Standard Library

https://docs.python.org/3/library/index.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs