JSON Debugging
JSON Number Precision Guide
Prevent JSON integer and decimal precision loss across JavaScript, APIs and databases by choosing explicit string or decimal representations. This reference is written for developers who need practical validation behavior, reviewable rules and safe examples rather than copied snippets with no explanation.
Recommended workflow
| Step | Why it matters |
|---|---|
| Classify the value | Separate identifiers, counters, money and scientific measurements before selecting a representation. |
| Check every consumer | Compare numeric ranges and decimal behavior in JavaScript, backend languages and databases. |
| Choose a contract | Transport oversized integers or exact decimals as documented strings when necessary. |
| Round-trip test | Serialize, parse, persist and return boundary values without relying on visual similarity. |
Starter snippet
unsafe JS integer: 9007199254740993 safer transport: "9007199254740993"Review checks
- Never model identifiers as numbers for arithmetic convenience.
- Define currency scale explicitly.
- Include maximum and minimum fixtures.
- Document rounding policy.
Common mistakes
- Trusting a formatter to preserve runtime precision.
- Using binary floating point for exact money.
- Converting to string only after precision was already lost.
Validation should help users correct input while protecting systems from bad data. Keep syntax checks, product policy, security review and deliverability checks separate.
Related Formalint references
Continue with Developer Data Validation Guide, Json Schema Guide, API Schema Drift Debugging.