KKitForma.

Language

EnglishEnglishTürkçeTurkishDeutschGermanGuide unavailable in this language · open toolsEspañolSpanishGuide unavailable in this language · open toolsFrançaisFrenchGuide unavailable in this language · open toolsPortuguêsPortugueseGuide unavailable in this language · open toolsItalianoItalianGuide unavailable in this language · open toolsNederlandsDutchGuide unavailable in this language · open toolsPolskiPolishGuide unavailable in this language · open toolsРусскийRussianGuide unavailable in this language · open toolsУкраїнськаUkrainianGuide unavailable in this language · open toolsSvenskaSwedishGuide unavailable in this language · open toolsNorskNorwegianGuide unavailable in this language · open toolsDanskDanishGuide unavailable in this language · open toolsSuomiFinnishGuide unavailable in this language · open toolsČeštinaCzechGuide unavailable in this language · open toolsRomânăRomanianGuide unavailable in this language · open toolsΕλληνικάGreekGuide unavailable in this language · open toolsالعربيةArabicGuide unavailable in this language · open toolsעבריתHebrewGuide unavailable in this language · open toolsفارسیPersianGuide unavailable in this language · open toolsاردوUrduGuide unavailable in this language · open toolsहिन्दीHindiGuide unavailable in this language · open toolsবাংলাBengaliGuide unavailable in this language · open toolsதமிழ்TamilGuide unavailable in this language · open toolsతెలుగుTeluguGuide unavailable in this language · open toolsमराठीMarathiGuide unavailable in this language · open toolsગુજરાતીGujaratiGuide unavailable in this language · open tools简体中文Chinese SimplifiedGuide unavailable in this language · open tools繁體中文Chinese TraditionalGuide unavailable in this language · open tools日本語JapaneseGuide unavailable in this language · open tools한국어KoreanGuide unavailable in this language · open toolsTiếng ViệtVietnameseGuide unavailable in this language · open toolsไทยThaiGuide unavailable in this language · open toolsBahasa IndonesiaIndonesianGuide unavailable in this language · open toolsBahasa MelayuMalayGuide unavailable in this language · open toolsFilipinoFilipinoGuide unavailable in this language · open toolsKiswahiliSwahiliGuide unavailable in this language · open toolsAfrikaansAfrikaansGuide unavailable in this language · open toolsMagyarHungarianGuide unavailable in this language · open toolsБългарскиBulgarianGuide unavailable in this language · open toolsHrvatskiCroatianGuide unavailable in this language · open toolsSrpskiSerbianGuide unavailable in this language · open toolsSlovenčinaSlovakGuide unavailable in this language · open toolsSlovenščinaSlovenianGuide unavailable in this language · open toolsLietuviųLithuanianGuide unavailable in this language · open toolsLatviešuLatvianGuide unavailable in this language · open toolsEestiEstonianGuide unavailable in this language · open toolsCatalàCatalanGuide unavailable in this language · open toolsEuskaraBasqueGuide unavailable in this language · open tools
← Questions & answers

KITFORMA · EDITORIAL ANSWER

How do I send a BigInt sequence through JSON without losing digits?

KitForma editorial guide. Send an integer beyond JavaScript’s safe number range as a validated decimal string, then reconstruct only that field as BigInt.

JavaScript & TypeScript →

Step-by-step answer

A normal JSON.stringify call cannot serialize a BigInt. Converting it to Number first can lose digits. Define the sequence field as a decimal string in the API contract and restore only that field on the receiving side. Runnable example:
javascript
const sequence = 9007199254740993n;
const wire = JSON.stringify({ sequence: sequence.toString(), sku: "00125" });
const message = JSON.parse(wire);
if (typeof message.sequence !== "string" ||
    !/^(0|[1-9]\d*)$/.test(message.sequence) ||
    message.sequence.length > 100) {
  throw new Error("Invalid unsigned sequence");
}
const restored = BigInt(message.sequence);
console.log(wire);
console.log(restored === sequence);
console.log(message.sku);
Expected result:
text
{"sequence":"9007199254740993","sku":"00125"}
true
00125
Why it works: The decimal digits cross the JSON boundary as text, avoiding floating-point rounding. The receiver checks the type, sign policy and a size limit before conversion. A general reviver that turns every digit string into BigInt would also change SKUs and other intentional strings. Scope and checks: Run in Node.js 24 or a modern browser with BigInt support. The 100-digit limit is this example’s policy, not a JSON limit. Define a tighter range if the receiving database uses a fixed-width integer. Leading-zero sequence strings are rejected; the unrelated SKU remains unchanged. Related tools and guides: Inspect the JSON transport text: https://kitforma.com/en/json-formatter/ Long JSON identifier guide: https://kitforma.com/en/community/questions/7aa10000-0000-4000-8000-000000000980/ Primary sources (reviewed 2026-10-08): ECMAScript — JSON.stringify and SerializeJSONProperty: https://tc39.es/ecma262/multipage/structured-data.html#sec-json.stringify

Sources and verification

Sources checked:

This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.

Discussion and community answers

Loading community…
KitForma

What would you like to do?