flashman
← All posts

JSON large integer precision debugging

Debug rounded JSON IDs and amounts by tracing parser limits, checking safe integer ranges, preserving exact strings, and testing every service boundary.

2026-09-02 · 6 min read · Rahul Chitturi

  • json
  • javascript
  • debugging

A JSON document can be syntactically valid while a large integer changes value after parsing. JSON defines a number grammar, but it does not require every implementation to preserve arbitrary integer precision.

JavaScript numbers represent integers exactly only through 9,007,199,254,740,991. Database IDs, nanosecond timestamps, monetary minor units, and counters can exceed that boundary and silently round before they reach a log or comparison.

Find the first lossy boundary

Capture a harmless value as source text, immediately after parsing, after each serialization step, and at the final consumer. Compare decimal strings rather than relying on formatted console output.

  • Check whether the producer emits a JSON number or quoted decimal string
  • Record language and database driver numeric types
  • Look for scientific notation introduced by serializers
  • Test values immediately below and above the safe integer limit

Choose an explicit contract

Represent opaque identifiers and exact values as strings when consumers do not perform arithmetic. If arithmetic is required, use an arbitrary-precision type and a serialization profile that every client supports.

Do not convert an already rounded number to a big-integer type; the original digits are gone. Fix the earliest parser or schema boundary and regenerate the value from an exact source.

A Flashman workflow

Use the JSON formatter to inspect the wire representation, number-base converter for exact integer fixtures, diff tool to expose changed digits, and units converter when byte or duration scales are involved.

Add contract tests for safe limits, negative values, very long integers, exponent notation, nulls, quoted values, and round trips through every supported runtime.

Try these tools