XML to JSON Migration

XML to JSON Migration

The Lesson

When migrating a live data format (XML to JSON), the key risk is not the conversion itself — it's proving that the new format produces identical behavior. The migration succeeded because the conversion was treated as a pipeline problem (convert, validate, prove equivalence) rather than a rewrite.

Context

A certification quiz application served 50+ exam files as XML, parsed client-side with DOMParser. The XML parser was ~200 lines of code handling namespace quirks, entity decoding, and cross-browser issues. JSON would eliminate all of this complexity and enable schema validation with standard tooling.

What Happened

  1. All XML files were converted to JSON using a Python script (xml_to_json_exam.py)
  2. A JSON Schema was written to formalize the data contract (certification.schema.json)
  3. A new ExamLoader class replaced XMLParser, adding schema validation on load
  4. The old XML parser was retained temporarily for comparison
  5. An equivalence test suite ran every question through both parsers and compared output field-by-field
  6. Only after 5,101 equivalence tests passed was the XML parser retired from the hot path

Key Insights

Related Lessons