--- id: 6a0dcc730cb92a616f86f0bf title: "Challenge 295: Schema Validator Part 1" challengeType: 29 dashedName: challenge-295 --- # --description-- Given an object (JavaScript) or dictionary (Python), determine if it matches the following schema: ```json { username: string } ``` - Extra keys are allowed # --hints-- `is_valid_schema({"username": "bob"})` should return `True`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_valid_schema({"username": "bob"}), True)`) }}) ``` `is_valid_schema({"username": "jen", "posts": 30})` should return `True`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_valid_schema({"username": "jen", "posts": 30}), True)`) }}) ``` `is_valid_schema({"username": ""})` should return `True`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_valid_schema({"username": ""}), True)`) }}) ``` `is_valid_schema({"username": 7})` should return `False`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_valid_schema({"username": 7}), False)`) }}) ``` `is_valid_schema({"posts": 25})` should return `False`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_valid_schema({"posts": 25}), False)`) }}) ``` # --seed-- ## --seed-contents-- ```py def is_valid_schema(obj): return obj ``` # --solutions-- ```py def is_valid_schema(obj): return isinstance(obj.get("username"), str) ```