How to find where a large JSON identifier lost a digit
Follow two neighboring order IDs through a JavaScript import, locate the first lossy conversion, and reconcile the affected records against the original export.
How we checked this guide. We compared a Node.js import with ADEMN’s formatter using two adjacent identifiers, then checked the number of distinct lookup keys after each conversion. Editorial and testing standards
Start with two orders that should stay distinct
Suppose a warehouse export has two orders, marked amber and blue for this exercise. The order IDs differ by one. Both rows reach the import service, but the lookup screen returns blue when someone asks for amber. Counting rows would miss this failure. The importer can read both rows successfully and still put the second record into the slot reserved for the first.
Copy the single line below into JSON Formatter and choose Minify. Both digit sequences should survive. Next, run the JavaScript example in a console. The labels are deliberately ordinary strings so they can identify the rows even if the IDs collide. Choose another synthetic marker if you reproduce this in an existing pipeline. Keep the original export available for comparison after each transformation.
[{"id":9007199254740992,"label":"amber"},{"id":9007199254740993,"label":"blue"}]const raw = '[{"id":9007199254740992,"label":"amber"},{"id":9007199254740993,"label":"blue"}]';
const rows = JSON.parse(raw);
const index = new Map(rows.map(row => [row.id, row.label]));
console.log(rows.length, index.size, index.get(rows[0].id));
// 2 1 blueExplain why one neighbor vanishes
The JSON text contains all the digits. JavaScript normally converts each unquoted numeric token into a Number when it parses the text. Around two to the power of 53, the spacing between consecutive representable positive integers changes. The even integer 9007199254740992 has an exact representation. The next integer falls halfway between representable neighbors and rounds to the same Number as its predecessor. No syntax error tells the importer that the two records now share a key.
Try the four inputs in the table separately. The last case matters because an integer outside the safe range can still print exactly as entered. Seeing the expected digits for one sample says little about the adjacent ID assigned tomorrow. Number.isSafeInteger checks whether the representation lies inside the range where every integer can be distinguished from its immediate neighbors. The subtraction or equality check you use to diagnose a collision is already working with the converted values.
| Raw number | String of parsed value | Number.isSafeInteger |
|---|---|---|
| 9007199254740991 | 9007199254740991 | true |
| 9007199254740992 | 9007199254740992 | false |
| 9007199254740993 | 9007199254740992 | false |
| 9007199254740994 | 9007199254740994 | false |
Find the first place the records become indistinguishable
Start at the producer and follow the same two labeled rows through a single run. At the source, export the identifier column as text or inspect it with a client that supports its integer type. At the HTTP boundary, read the response body as text. A browser network panel can show a convenient object preview reconstructed from parsed values. The raw response and the preview can therefore give different answers to the question about the final digit.
Take another reading immediately before the database write. Inspect the type of the bound parameter as well as its displayed value. A database column capable of storing a 64-bit integer can faithfully store an already rounded argument. If the outgoing body has two distinct IDs and the bound parameters coincide, narrow the search to the decoder, mapping code, and database driver on that path. If the body already contains a collision, move the observation point upstream to the export query and serializer.
Repeat the check when reading the records back. If two identifiers are distinct in storage but coincide in a dashboard, the repair belongs in the read path. Comparing the label and exact key at each boundary avoids retrying writes that were correct the first time. Save redacted fixtures with type annotations alongside the result so someone else can reproduce the first discrepancy.
Choose an interchange type that survives the return journey
For identifiers that people look up, compare, or embed in URLs, a decimal string is often a suitable contract. Change the producer to emit the two original digit sequences as quoted strings, then verify that readers preserve them as strings through indexing and serialization. A code field such as 00042 gives another reason to specify the type explicitly. The quoted string retains its five characters. The same five digits cannot form a valid unquoted JSON number with leading zeros.
A receiver may already require an integer. Check its schema before changing a field type. Use an integer-aware decoder and an exact storage type on that path, then test the actual driver and outbound serializer with the neighboring values. JavaScript BigInt can hold the original digits when constructed from an exact decimal string. Feeding it a rounded Number preserves that rounded value. Plain JSON.stringify also throws on a BigInt unless the caller provides a serialization strategy. Define the outbound representation along with the inbound one.
One more check belongs in migration testing. An old consumer may sort identifiers numerically for display. A string sort places 10 before 2 because it compares the first character. Decide whether order has meaning for this field. If a list needs chronological order, carry an explicit timestamp or sequence with its own documented type. That lets the identifier stay exact while paging and display use the intended ordering.
const rows = JSON.parse('[{"id":"9007199254740992"},{"id":"9007199254740993"}]');
console.log(new Set(rows.map(row => row.id)).size); // 2
console.log(String(BigInt(rows[1].id))); // 9007199254740993
console.log(String(BigInt(Number(rows[1].id)))); // 9007199254740992Reconcile records already imported
Retrieve the original export or query the authoritative system for the affected interval. Use a stable independent key such as a source transaction reference to align the records. The amber and blue labels play that role only in this fixture. A production label that can change or repeat cannot identify a record on its own. Compare the number of distinct source IDs, distinct destination keys, and matched independent references before proposing corrections.
If both original rows are available, reconstruct the intended mapping from those rows and check dependent lookups individually. If the only surviving artifact contains the rounded value, several original integers may fit the evidence. Flag that record for source verification. Adding one to every suspect ID would also change genuine even IDs. For a final acceptance check, replay the pair twice into an isolated import target. Each source reference should still retrieve its own record after the second pass, with exactly two distinct keys and the original digits on export.