JSON in Python — Python Technical Interview Questions & Answers

JSON in Python

JSON in Python

  • JSON is text data. Python’s json module converts. json.loads: JSON string → dict/list. json.dumps: Python object → JSON string. json.load / json.dump work with files. JSON object ↔ dict. JSON array ↔ list. The extra s in loads/dumps means string.
  • APIs send JSON. You dumps a dict of marks, send it, loads it back. Don’t confuse dump (file) with dumps (string). That letter is the MCQ.
  • JSON in Python — output: Asha then {"name": "Asha", "marks": 90}. loads parse, dumps text.

Technical Interview Tip: s in loads/dumps means string.

Code Examples for JSON in Python

Example

# JSON
import json
s = '{"name": "Asha", "marks": 90}'
d = json.loads(s)
print(d["name"])
print(json.dumps(d))

JSON in Python — output: Asha then {"name": "Asha", "marks": 90}. loads parse, dumps text.

How to Explain JSON in Python to an Interviewer

Explain JSON as if you are teaching a junior — definition, then one tiny script.

Loads / dumps = string Load / dump = file

What does the example print, and why?

JSON in Python — output: Asha then {"name": "Asha", "marks": 90}

What mistake do freshers make with JSON?

Dict ↔ object, list ↔ array