What does JSON.parse('{"limit":1e400}').limit return in Node.js? It’s valid JSON. By the time a validator gets the value, it’s Infinity.
That detail mattered when I moved spec-lane, a CLI that keeps development workflow records, from Zod 3 to Zod 4. A budget limit that used to pass validation could start failing even though the user hadn’t edited the file. Compare the two releases, v0.15.0 and v0.16.0, and all ten JSON Schemas we ship are byte-for-byte identical. What did we have to change, then?
How many retries can an integer hold?
The old schema defined a retry count as z.number().int().nonnegative().default(0). Most of the intent reads straight off the line: a missing count means zero, and half a retry makes no sense. But what about this count?
const { retry_count: n } = JSON.parse('{"retry_count":9007199254740992}');
Number.isInteger(n); // true
Number.isSafeInteger(n); // false
n === n + 1; // true
That number is exactly 2 to the power of 53. JavaScript can represent it, but it can’t distinguish it from the next integer when it does the addition. Zod 3’s integer check accepted the number. Zod 4’s .int() requires a safe integer and rejects it.
For a new API, rejecting the value is a sensible default. A reader for existing files has a different obligation. If it’s going to start rejecting something it used to accept, I’d like that to be a deliberate format change. In spec-lane, the compatibility schema checks Number.isInteger and the retry field keeps its nonnegative constraint.
There are two regression tests worth reading together. The first puts that large integer in an old-format workflow record and checks the value coming out of the reader. The second puts 1.5 in the same field and expects the reader to throw. The huge count is a test input. Without the test for 1.5, removing the integer check altogether would also make the first test pass. Retry count tests
A JSON file can deliver infinity without spelling it
Back to the budget limit. Zod 3’s z.number().positive() accepted positive infinity. Zod 4’s z.number() accepts only finite numbers. It’s tempting to dismiss the difference for a file-based CLI since you can’t write the token Infinity in JSON. You can, however, write a perfectly ordinary exponent that overflows a JavaScript number.
JSON.parse('{"limit":1e400}').limit; // Infinity
JSON.parse('{"limit":-1e400}').limit; // -Infinity
The parser has already made this conversion before Zod sees the input. For the budget, spec-lane now takes the union of a positive finite number and the literal Number.POSITIVE_INFINITY. Negative infinity still fails. The project’s tests pass both numeric values directly into the budget schema. The two lines above show how a file can supply those same values. Budget tests
What the empty diff actually bought us
The generated JSON Schemas have their own readers. A Python consumer can validate the structure of a workflow file without loading any TypeScript. During the migration, spec-lane switched generators to Zod 4’s built-in z.toJSONSchema() and kept the published Draft 7 representation. Comparing those ten files across release tags is a meaningful check for consumers of those artifacts. It doesn’t run the CLI’s parser.
The test I’d borrow for another project gives the same structural fixtures to Zod and to Ajv, with Ajv reading the published JSON Schema. A valid fixture must pass both, and an invalid one must fail both. Then there are the smaller, field-specific tests for the behavior that matters when opening old records, like the retry count and the budget limit. Generator · Zod/Ajv comparison
If you maintain a form with saved drafts, an input from the previous version of the form is a good place to start. Put it in the dependency-update PR beside an example you’ve always rejected. When the next validator upgrade disagrees, you have two concrete inputs to discuss and a decision to make about your own format.
Top comments (0)