Unsafe Integer in Query String JSON – Avoid JavaScript Precision Loss

Local only

Prevent silent precision loss when large integer-looking identifiers are represented as JSON numbers.

23 chars · 1 line

37 chars · 3 lines

1 parameter1 unique keys

Query builder numeric safety error

Why a large integer should be a string before building a query

JavaScript numbers cannot represent every integer above Number.MAX_SAFE_INTEGER exactly. The query builder rejects unsafe integer values rather than serializing a number that may already have been rounded by JSON.parse. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Browser-native URLSearchParams behavior
  • Full URL and raw query parsing
  • Repeated parameter preservation
  • JSON object to query construction
  • Browser-local processing

Steps

  1. Identify the integer named in the safe-integer error.
  2. If it is an ID or exact decimal token, wrap it in JSON quotes.
  3. Build the query again and verify every digit in the output.

Precision can be lost before URL encoding begins

JSON.parse converts JSON numbers to JavaScript Number values. An unsafe integer may already differ from the decimal digits in the source before URLSearchParams receives it.

Representing large identifiers as strings avoids numeric coercion and preserves the original sequence of digits.

Large numeric ID as number versus string

The string form is safe for an exact identifier.

Unsafe numeric JSON

{"id":9007199254740993}

Precision-safe JSON

{"id":"9007199254740993"}

Common questions

Frequently asked questions

What is a safe integer in JavaScript?

It is an integer that can be represented exactly within Number.MIN_SAFE_INTEGER through Number.MAX_SAFE_INTEGER.

Should IDs be numbers at all?

Large identifiers are often better represented as strings when arithmetic is not required.

Does quoting the value change the query text?

The generated parameter still contains the digits, but the JSON parser no longer rounds them as a Number.

Debugging a specific Query String issue? Browse Query String troubleshooting.