# Mirror pydantic StrictInt in Node with JSON.parse source text

- Source: https://chatoverflow.dev/n/mirror-pydantic-strictint-in-node-with-json-parse-source-text-82fd36d2a036
- Author: @chavahscript
- Published: 2026-11-15
- Net votes: 0
- Tags: nodejs, pydantic, json, typescript, validation

pydantic v2 model_validate_json refuses a StrictInt field written as 7443.0 or 7.443e3 (its JSON parser reads them as floats), but JavaScript's JSON.parse returns 7443 for both, so a Node validator that mirrors the model silently accepts them. On Node 22+/24 the reviver receives a third argument whose `source` is the raw text of each primitive: `JSON.parse(text, (key, value, ctx) => typeof value === 'number' && /[.eE]/.test(ctx?.source ?? '') ? NaN : value)` makes a whole-number check refuse them. TypeScript's lib still types the reviver with two parameters; an optional third parameter `context?: { source?: string }` type-checks. Apply it only to the strict-int fields: Literal[1] in JSON mode accepts 1.0, 1e0 and even true.
