No — and the gap is wider than it sounds. A round trip proves that one library agrees with itself, which is a weaker claim than "the bytes say what I wrote". I wrote five values, read each one back with the writer that produced it, then read the same bytes with a different implementation of the same format. The round trip passed four of the five. Of those four, one value came back changed with no error anywhere, one was refused outright by the other reader, and one agreed only because both readers ran on the same machine.
The mistake is easy to make because the test is cheap. Write a file, read it back, assert equality, watch it go green. The assertion is true and it says nothing about the format, because the producer and the consumer are the same code. A producer that writes something the format does not allow will read that thing back happily. Whatever you agreed with yourself, you keep agreeing with.
The five cases
One script, two readers: the writer's own library (Python's json and csv), and a second implementation of the same format (JSON.parse and Date in Node) where the format has one.
| case | bytes written | writer's own reader | independent reader |
|---|---|---|---|
| float infinity | {"n": Infinity} |
json.loads → equal to what was written |
JSON.parse → SyntaxError: Unexpected token 'I' |
| integer past 2^53 | {"id": 9007199254740993} |
json.loads → 9007199254740993, exact |
JSON.parse → 9007199254740992, no error |
| timestamp with no zone | {"at": "2026-11-08T16:21:08"} |
fromisoformat → equal, tzinfo=None |
new Date(...) → 2026-11-08T08:21:08Z |
| CSV with a missing value | a,\r\n |
csv.reader → ['a', ''], not equal |
— |
| CSV with a comma inside a field | "x,y",z\r\n |
csv.reader → ['x,y', 'z'], equal |
naive split(",") → 3 fields |
The round trip caught one of the five. Here is what the other four were doing.
The value the format does not have
Python has a float infinity, so json.dumps writes Infinity, and json.loads accepts it and hands back a float infinity — equal to what I wrote, so the assertion is green. The file is still not JSON. JSON has no infinity; Infinity is one of the literals Python's encoder emits by default and one of the ones its decoder tolerates (allow_nan is true on both sides).
This is the friendly failure, because the other reader refuses it: a loud SyntaxError at the moment of reading. If both the producer and the consumer are Python, nothing is wrong until the day a different consumer arrives — and then it fails there, far from the test that would have caught it.
The value that came back different
9007199254740993 is 2 to the 53rd plus one. It fits in a Python integer exactly, and Python writes out all of its digits. The other reader returned 9007199254740992, the neighbouring representable double, with no error, no warning, nothing.
This is the row I would keep if I could keep only one. The round trip is not merely uninformative here, it is active reassurance: it says the number survived, and by "the number" it means the number in this language. The consumer's number has changed, silently. If that value is an id, you look up a different row. If it is a nanosecond timestamp, the ordering is wrong by a hair. Either way the log stays empty.
The fix is not a better writer. It is the decision that a 64-bit integer crossing a language boundary travels as a string, or carries a range assertion — because "JSON number" means a double everywhere except in the implementations that chose to spend the extra digits.
The value that agreed for the wrong reason
I wrote 2026-11-08T16:21:08: a wall-clock reading with no offset. fromisoformat gave back an equal datetime whose tzinfo is None — equal because neither side has ever had a zone. The other reader turned the same string into 2026-11-08T08:21:08Z.
That looks like agreement, and on the machine I ran this on it was: both readers sat in the same +08:00 local zone, so the offset the other reader assumed was the offset I meant. Move the file to a reader in another zone and the digits do not change but the instant does — eight hours away, with no error in either direction. Two readers passed, and the bytes still do not answer the question "which instant is this".
There is no clever reading here. A timestamp without an offset is a document that depends on a fact not present in it, and the repair is to write the offset in: datetime.now(timezone.utc).isoformat() ends in +00:00 and means one thing everywhere.
The one the round trip did catch
csv.writer writes None as an empty field, and csv.reader gives back ''. The comparison fails, so the assertion goes red and I find out. This is the round trip working, and it is worth seeing why: the disagreement is not about the format, it is about one library's own model of a missing value. Both sides are the same code, and that code has two notions of "nothing".
Note what it still does not tell you. After the assertion is patched, an empty field and an absent one are the same bytes. CSV has no null, so "was this field missing or empty" is a question your schema has to answer, not your writer.
The row where the second reader is the wrong one
The writer's reader returned ['x,y', 'z'], which is correct: quoting is how a comma stops being a separator. My "independent reader" for this row was a naive split(","), and it returned three fields — because it implements splitting, not CSV. This is the counterweight to the first two rows. A second reader disagreeing does not prove the first one is wrong, and you have to know which layer each reader actually implements. split(",") and csv.reader are not two implementations of one format; one of them implements the format and the other is a string operation wearing its name.
What a round trip is good for
It is a wiring test, and a good one. It catches the file landing somewhere you did not expect, an encoding that mangles text on the way out, a schema change that dropped a key, a serializer that forgot a field. Those are real failures of the pipeline, and the round trip is the cheapest instrument that sees them.
What it cannot be is a validity test, because validity is a property of the format and a round trip is a property of the implementation. Naming the test after what it does is most of the fix: test_pipeline_round_trips is honest, test_file_is_valid is a claim nobody checked.
What I do instead, in this order
- Make the writer refuse what the format forbids.
json.dumps(obj, allow_nan=False)turns the infinity case into an error at write time, where it is cheap. - Read the bytes with something that is not the writer, whenever the file leaves the process. Another language's parser, a schema validator,
jq— any of them, as long as it shares no code with the producer. One case per test is enough when it is the case your data actually contains. - Put an offset on every timestamp. It is one line, and it removes a whole class of "it worked on my machine".
- Decide what a missing value means before the format decides it for you, because CSV, JSON and your database each answer differently.
The boundary of this measurement
Five cases, one writer (Python 3.13.9), one independent reader (Node 22.16.0), one machine in +08:00, run on 2026-11-08. This is not a survey of serialisation bugs. It is five probes, each chosen because the round trip cannot see that particular failure. Your format has its own, and the way to find it is the same one line: write the value, read it back, then read it with somebody else's parser and compare what you got — not just whether it parsed.
Comments
Join the discussionNo comments yet. Be the first to comment.