Data Formats (JSON, YAML, TOML, XML, CSV) Module 1
Foundations: choosing formats and handling text interview questions
Interview questions on “Foundations: choosing formats and handling text”: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
A format's syntax and its data model: how do they differ?
The syntax is the set of rules for the text itself: which characters are allowed, how strings are quoted, what separates values. It decides whether a file can be parsed at all. The data model is the set of values you get after parsing: JSON gives objects, arrays, strings, numbers, true, false and null; CSV gives rows of text fields; XML gives elements, attributes and text. Two files can follow the syntax perfectly and still differ in what their data model can hold, which is why the same order read from JSON keeps 37900 as a number, while from CSV it comes back as the text "37900". Neither layer checks meaning: a schema states which values are allowed, such as a whole number of paise.
From the lesson Choosing a data format: JSON, YAML, TOML, XML, CSV
-
Fresher to mid
Why is CSV called a format without types?
Answered in the lesson Choosing a data format: JSON, YAML, TOML, XML, CSV
-
Fresher to mid
What is a byte-order mark, and why does JSON care?
Answered in the lesson UTF-8, BOMs and line endings in data files
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
Your team wants to move a service's settings from config.json to config.yaml so that people can write comments. What would you check before agreeing, and what would you put in place so that the move cannot change the value of any setting?
- What it tests
- Knowing that YAML parsers type plain values by their version and schema, choosing the loader on purpose, quoting risky values, validating parsed values, and proving the move with a value-by-value comparison.
- First step
- Ask which parser will read the file, and which YAML version and schema it follows. JSON text is valid YAML 1.2, but people will not keep writing JSON: they write plain YAML, whose values are typed by the parser. Psych, a YAML 1.1 parser, read backup: 02:30:00 as the number 9000.
- Follow-ups
-
- How would you prove that the move changed no value?
- Which values would you quote, and why?
- What would you add to CI?
From the lesson Choosing a data format: JSON, YAML, TOML, XML, CSV
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Finance wants a daily export of orders they can open in a spreadsheet, and the billing service must import the same data. Which format or formats would you produce, and how would you keep amounts, ids and times exact for both?
- What it tests
- Producing one file per consumer from one source, keeping amounts in minor units, ids as text and times with their offset, and knowing the spreadsheet's 15-digit limit and how it reads columns.
- First step
- Name the two consumers and what each needs. People need rows and columns in a spreadsheet, so CSV; the service needs exact types, so JSON or JSON Lines. Write both from the same records in one job, with the same field names and the same rules for amounts, ids and times.
- Follow-ups
-
- Why not give the billing service the CSV file too?
- How do you keep the spreadsheet from changing long ids?
- How do you check that the two files agree?
From the lesson Choosing a data format: JSON, YAML, TOML, XML, CSV
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A nightly import reads a CSV export with csv.DictReader. Since the export moved to a new tool, it fails with KeyError: 'name', although the first line of the file still reads name,city. What happened, and how do you fix the import and protect it from the next change of exporter?
- What it tests
- Recognising a UTF-8 byte-order mark in the first header, decoding with utf-8-sig, opening CSV with newline='', and checking the header and the bytes at the boundary.
- First step
- Print repr() of the header keys, or the first bytes of the file in hex. The first key is '\ufeffname' and the file starts EF BB BF: the new tool writes a UTF-8 byte-order mark, which plain utf-8 decoding keeps as part of the text.
- Follow-ups
-
- Why did the KeyError say name, and not the strange character?
- Would you strip the BOM in the reader or ask the exporter to drop it?
- What check would catch the next change of exporter at once?
From the lesson UTF-8, BOMs and line endings in data files
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A job reads a CSV file, changes one column and writes it back. A checksum comparison then reports every row with a two-line address as changed, although nobody edited the addresses. Where did the change happen, and how would you make the round trip exact?
- What it tests
- Knowing that RFC 4180 fields may hold line breaks, that universal newlines rewrite CRLF inside quoted fields, and that the csv module needs files opened with newline='' for reading and writing.
- First step
- Compare the bytes of one changed row before and after: the quoted address held CR LF and now holds LF. Then look at how the job opened the files. Without newline='', Python's universal newlines turned the CR LF inside the quotes into LF before the csv module read it.
- Follow-ups
-
- Why does the csv module not notice the change?
- Would opening in binary mode be a better fix?
- How would you test that the round trip is exact?
From the lesson UTF-8, BOMs and line endings in data files
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
All Data Formats (JSON, YAML, TOML, XML, CSV) interview questions · The Data Formats (JSON, YAML, TOML, XML, CSV) track