Brief
Validate JSON stream changes and preserve incompatible messages for investigation without losing recognized commands.
Voss shows a table where OPEN-18 appears to disappear after a producer update. Mara suspects a JSON contract break; Imani refuses to have unknown messages erased. Explain what the reader accepts and quarantines before the fictional meeting. The countdown belongs to the plot; the exercise has no timer.
Your mission
- Name the required fields and types.
- Explain why the v2 message containing device remains readable to this practice reader.
- Explain the v3 problem and safe handling.
- List accepted commands and quarantined event IDs.
How to check your work
- schema_version integer; event_id, command_id, credential strings.
- v2 retains required fields, device is optional, and this reader supports v2.
- v3 renames command_id; keep raw E4 in quarantine.
- OPEN-17 and OPEN-18 accepted; E4 rejected without silent loss.
Course example
import json
raw_messages = [
'{"schema_version":1,"event_id":"E1","command_id":"OPEN-17","credential":"SUPPLIER-SVC"}',
'{"schema_version":2,"event_id":"E2","command_id":"OPEN-18","credential":"SUPPLIER-SVC","device":"KIOSK-2"}',
'{"schema_version":3,"event_id":"E4","operation_id":"OPEN-19","credential":"SUPPLIER-SVC"}',
]
accepted, quarantined = [], []
for raw in raw_messages:
message = json.loads(raw)
valid = (
type(message.get("schema_version")) is int
and message["schema_version"] in (1, 2)
and all(type(message.get(field)) is str
for field in ("event_id", "command_id", "credential"))
and ("device" not in message or type(message["device"]) is str)
)
if not valid:
quarantined.append(message.get("event_id", "UNKNOWN"))
continue
accepted.append(message["command_id"])
print("accepted", accepted)
print("quarantined", quarantined)