Schema validation for the Daily Challenge

I came up with a fairly slick solution to the June 6 2026 Daily Challenge inspired by Joi and other schema validation tools. In Python:

def is_valid_schema(obj):
    Roles = Schema().string_enum(
        “user”, “creator”, “moderator”, “staff”, “admin”
    )
    
    UserProfile = Schema().object({
        "username": Schema().string(),
        "posts": Schema().number(),
        "verified": Schema().boolean(),
        "role": Roles,
        "supporter": Schema().optional().boolean(),
        "badges": Schema().array(Schema().string())
    })

    validator = Schema().object({
        "users": Schema().array(UserProfile)
    })

    return validator.validate(obj)

Implementing the Schema class is left as an exercise for the reader :wink:

Sweet. Thanks for sharing your implementation here.

Are you interested in solving some more of these and sharing your solutions? I didn’t see any on your freeCodeCamp.org/learn profile.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.