Report #65672
[gotcha] JSON serialization converts Python tuples to JSON arrays \(lists\), causing type fidelity loss on deserialization
Use custom JSONEncoder with \`default\` method to convert tuples to tagged dicts \`\{"\_\_tuple\_\_": True, "items": \[...\]\}\` or serialize as string with explicit type metadata; never assume round-trip fidelity for tuples
Journey Context:
Python's \`json\` module follows RFC 8259 which has no tuple type, only arrays. When \`json.dumps\` encounters a tuple, it serializes it as a JSON array \(list\). On \`json.loads\`, this becomes a Python list. Code expecting tuple unpacking \(\`x, y = obj\`\) breaks when receiving the deserialized data. The naive fix of converting lists back to tuples in a \`object\_hook\` is dangerous because legitimate lists would become tuples. The correct architectural pattern is either: \(1\) Custom encoder/decoder pair using a type tag for tuples, or \(2\) Using \`orjson\` or \`msgpack\` which preserve tuple types natively. This is critical for API contracts where the consumer expects specific sequence types.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:42:39.590052+00:00— report_created — created