JSON integer round-trip experiment / JSON 整数往返实验 / JSON 整数往復実験
Recorded: 2026-10-30

Run / 运行 / 実行
  Keep json-integer-roundtrip-lab.py and json-integer-roundtrip-node.mjs together.
  Put Node.js on PATH, then run:
    node --version
    python3 json-integer-roundtrip-lab.py > rerun.json
  Python standard library and Node.js built-in modules only. No package install.
  Node.js must support JSON.parse reviver context.source; the script asserts it.
  本次环境 / 今回の環境: macOS 27.0.1, arm64, CPython 3.12.14, Node.js v22.23.1.
  Scripts read fixed fixtures and print JSON; they do not open network sockets,
  connect to databases, or change files. The shell redirect writes rerun.json.

Method / 方法
  Python int -> json.dumps compact numeric field -> actual Node.js subprocess
  -> native JSON.parse -> native JSON.stringify -> Python json.loads.
  Compare with source string fields travelling through the same two runtimes.
  The report stores large integers as strings so its evidence survives another
  native JavaScript JSON reader. Number display, represented integer (observed
  via BigInt(value)), and the Python integer after the return trip are separate.

Fixtures / 固定输入 / 固定入力
  0, 42, 9007199254740991, 9007199254740992, 9007199254740993,
  9007199254740994, 9007199254740995, -9007199254740993,
  9223372036854775807, -9223372036854775808,
  18446744073709551615, 1000000000000000000.
  These are synthetic boundary fixtures, not actual user or business IDs.

Recorded assertions / 已验证 / 検証済み
  12 integer cases: all initially preserved by Python int parsing.
  5 changed at native Node.js numeric parsing; 6 changed on the full numeric trip.
  12/12 source string trips preserved the complete original string.
  Numeric keys 9007199254740992 and 9007199254740993 collide in Map (size 1).
  Original string keys remain distinct (size 2).
  BigInt(parsed value) in reviver yields 9223372036854775808 for the main case.
  Comparing the parsed main case to the unsafe Number literal
  9223372036854775807 returns true because that literal is rounded too;
  comparison to the exact BigInt literal 9223372036854775807n returns false.
  BigInt(context.source) yields the original 9223372036854775807.
  Default JSON.stringify of the BigInt field throws TypeError; explicit string
  output round-trips correctly. BigInt.prototype is not patched.
  BigInt(context.source) on 9.007199254740993e15 throws SyntaxError.
  That exponent token also uses Python float and represents 9007199254740992.
  1.0000000000000001 parses to Number 1 and passes Number.isSafeInteger;
  safe-integer testing of a parsed value does not validate its original token.
  readId: 4 accepted, 13 rejected. Its explicit sample contract is canonical
  nonnegative ASCII decimal strings <= 9223372036854775807, with no leading zeros
  except the single string "0". Empty, non-string, signed, exponent, whitespace,
  fullwidth and out-of-range inputs are checked. This is not a universal ID rule.

Limits / 限制 / 制約
  Offline cross-runtime integration only. No HTTP, browser, database driver,
  third-party JSON library, generated SDK or production service was tested.
  Numeric boundary cases include signed/unsigned values; readId independently
  illustrates a narrower nonnegative signed-int64-range ID contract.
  A source-text reviver requires original source, engine support and field rules;
  the included one-field example is not a generic lossless number parser.
  Changing number fields to string fields requires coordinated API compatibility.
  Counts are fixed-fixture outcomes, not failure rates for randomly generated IDs.

Sources checked on 2026-10-30 (linked in both article versions)
  https://www.rfc-editor.org/rfc/rfc8259.html#section-6
  https://docs.python.org/3.12/library/json.html#json.load
  https://docs.python.org/3.12/library/stdtypes.html#numeric-types-int-float-complex
  https://tc39.es/ecma262/2026/multipage/ecmascript-data-types-and-values.html#sec-ecmascript-language-types-number-type
  https://tc39.es/ecma262/2026/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring
  https://tc39.es/ecma262/2026/multipage/structured-data.html#sec-serializejsonproperty
  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger
  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter
  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json

Files in the ZIP: the two scripts, the recorded JSON report, this README.
Only original experiment files are bundled; no external page content is copied.
