Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article7 min readViews1

Order ID Changed Without Error: How a JSON Number Breaks the External Identifier

I demonstrate with a verified Node.js example why the external ID 9007199254740993 silently changes after JSON.parse, how to enforce a string contract, and how to verify duplicate delivery in integration with 1C-Bitrix.

Comments 0

Two different brass labels pass through a glass prism and produce a single shared optical image
In this article

If an identifier relates to an order, product, or product variant and is not used in arithmetic, pass it as a string in JSON. The numeric value 9007199254740993 becomes 9007199254740992 after JSON.parse in JavaScript—without exception and without warning. For integration, this means the risk of incorrect matching, duplicates on re-delivery, or updating the wrong record.

Below is a reproducible example for a custom adapter in Node.js and the contract rules. It does not describe an error in the standard 1C to 1C-Bitrix: Site Management exchange; the issue arises at the system boundary when developers themselves declare an opaque identifier as a number.

Minimal example: valid JSON, incorrect identifier

The check was performed on December 4, 2026, in Node.js 24.22.3 with V8 13.6.233.17-node.63. The script only parses fixed strings in memory: it does not modify files, the network, the database, or the working store.

Save the code to a separate file external-id-json-test.mjs inside a temporary directory:

const unsafePayload = '{"external_id":9007199254740993}'; const safePayload = '{"external_id":"9007199254740993"}'; const leadingZeroPayload = '{"external_id":"000123"}'; function readExternalId(payload) { const message = JSON.parse(payload); if (typeof message.external_id !== 'string') { throw new TypeError('external_id must be a JSON string'); } if (!/^[0-9]{1,20}$/.test(message.external_id)) { throw new RangeError('external_id must contain 1–20 decimal digits'); } return message.external_id; } const unsafe = JSON.parse(unsafePayload); console.log(`unsafe parsed: ${unsafe.external_id}`); console.log(`unsafe exact: ${String(unsafe.external_id) === '9007199254740993'}`); const safe = readExternalId(safePayload); console.log(`safe parsed: ${safe}`); console.log(`safe replay stable: ${safe === readExternalId(safePayload)}`); console.log(`leading zero preserved: ${readExternalId(leadingZeroPayload)}`); for (const payload of [unsafePayload, '{"external_id":"12.3"}']) { try { readExternalId(payload); } catch (error) { console.log(`rejected: ${error.message}`); } }

Run it as a regular user:

node external-id-json-test.mjs

Expected and actual output:

unsafe parsed: 9007199254740992 unsafe exact: false safe parsed: 9007199254740993 safe replay stable: true leading zero preserved: 000123 rejected: external_id must be a JSON string rejected: external_id must contain 1–20 decimal digits

The key line is "unsafe parsed". The sender wrote 9007199254740993, but the receiver already sees 9007199254740992. Converting back to a string does not restore the lost unit: String(message.external_id) will return a distorted value.

Why the parser does not treat this as an error

JSON syntax allows such a number. However, RFC 8259 warns about compatibility limitations: integers in the range from −(2^53)+1 to (2^53)−1 can be expected to be exact in widely used implementations. The value 9007199254740993 lies beyond this limit.

In JavaScript, the Number type stores numbers in double-precision format. ECMAScript defines Number.MAX_SAFE_INTEGER as 9007199254740991 and separately shows that 9007199254740992 and 9007199254740993 are represented by the same Number value. Therefore, JSON.parse successfully returns a number, but identity with the original text is already lost.

This does not mean that any JSON parser in any language will necessarily corrupt the value. Some libraries can preserve arbitrary precision. The catch is different: a contract depending on a specific parser and its settings does not transfer well between services. An opaque identifier as a string eliminates this dependency.

A string is needed not only because of 2^53

An identifier has a form, not a numeric value. The values 000123 and 123 may represent different objects at the source. If the field is declared as a number, leading zeros disappear even before business logic. Tomorrow the source may add a warehouse prefix, a hyphen, or switch to UUID, and the numeric contract will have to be broken.

The regular expression from the example is not a universal standard. It fits only the educational condition "from 1 to 20 decimal digits". For real integration, define your own grammar: allowed characters, length, case, leading zeros, and the possibility of a composite key.

How to lock in a safe contract

  • Pass external_id as a JSON string at all stages: sender, queue, adapter, message log, and receiver.
  • Check the type immediately after parsing the message. Reject numbers; do not "fix" them via String(), as precision may have already been lost.
  • Store the external identifier separately from the internal numeric order or product ID. Enforce uniqueness for the "source + external ID" pair.
  • Agree on string comparison. Case-insensitive database collation may unexpectedly treat abc and ABC as identical if the source distinguishes case.
  • On redelivery, first search for an exact match, then update the existing object. Create a new record only if no match is found.

In a small example, replaying the same string message yields safe replay stable: true. This verifies read stability but does not prove idempotency for the entire integration. A production adapter requires a unique constraint in the mapping store and an atomic "find or create" operation; otherwise, two parallel handlers may still create duplicates.

Where this fits in the 1C-Bitrix integration

In a custom integration, verify the external key before calling the "1C-Bitrix: Site Management" API. First, the adapter validates the string and searches for it in the mapping table, then retrieves the internal ID of the element, product variant, or order, and only then performs the update.

Do not substitute an external key with Bitrix's internal ID. The internal ID belongs to a specific database and may not match after migration involving object recreation or import. Restoring a correct backup does not change the ID by itself. An external key belongs to the source and is needed so that a repeated message finds the same object.

If the integration already creates duplicates, first compare the actual external keys and the message route. The section about product duplicates during exchange lists other causes as well: changing identifiers, different catalogs, and re-creation instead of updates. For exchange requirements before development, the specification for integrating an online store with 1C will be useful.

If the numeric contract is already working

Do not change the field type en masse blindly. First, export the mapping table and a backup, then identify values outside 9007199254740991, leading zeros in the source system, and possible collisions. Separately check whether the same object is already recorded under two distorted keys.

It is more convenient to make the transition versioned: the new sender sends a string, the receiver temporarily accepts only explicitly agreed message versions, and the old numeric format is logged and either rejected or processed via an isolated compatible route. The migration completion condition is zero messages in the old format over an agreed period and a successful re-run of control identifiers.

Acceptance testing

  • 9007199254740991 is preserved unchanged but still arrives as a string: the identifier does not become a number just because it fits within the safe range.
  • 9007199254740993 passes through as a string and is returned byte-for-byte with the same value.
  • 000123 preserves leading zeros.
  • A numeric external_id is rejected at the boundary, and the error contains a safe description without the full client message.
  • Repeating the same message updates the same object and does not create a duplicate.
  • Two parallel repeats hit the uniqueness constraint on the pair "source + external ID".
  • An invalid character, an empty string, and exceeding the length limit produce a predictable failure before contacting the Bitrix API.

The result criterion is simple: the identifier remains an exact string from the incoming message to the mapping table, and a repeated delivery finds the original internal object. If the field becomes a Number at any point, the contract is not yet fixed.

Discussion 0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.