Your question is Validate Objects Against a Schema. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Amplitude Experiment and Analytics services receive structured event payloads. Implement a validator that checks whether an object conforms to a recursive schema containing required fields, data types, nested objects, and arrays.
The schema uses nodes with type, and optionally required, properties, items, and additionalProperties. Supported types are string, number, boolean, null, array, and object. Return an object containing valid and an ordered errors list. Report errors in traversal order using paths such as payload.user.id and payload.items[0]. A missing required field should produce missing: <path>. A type mismatch should produce expected <type>: <path>. When additionalProperties is false, report unexpected: <path> for undeclared fields.
def validate_payload(payload, schema):