How to Freeze JSON Serializer Output Before Refactoring Call Sites
Codebases that scatter json.dumps calls with inconsistent flags risk silent wire-format changes when those calls are later consolidated into a single helper function. Parameters like ensure_ascii, sort_keys, separators, and custom default handlers each affect the exact bytes produced, and downstream systems such as gateways and log processors may break without any test failure. The recommended approach is to pin the exact UTF-8 bytes output by every distinct dumps call site before extracting a shared serializer. Pins should record the byte output, the exception type raised on invalid input, and whether a default handler was present — not just parsed Python dict equality. Once byte-level fixtures are committed and passing, a single serializer function can be safely extracted without merging incompatible serialization dialects.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in