Read Validated JSON Preferences

Parse JSON preferences and return exactly theme and notifications. Defaults are {"theme":"light","notifications":True}. Accept only theme strings light/dark and actual boolean notifications; invalid fields keep their defaults. Ignore unknown keys. Invalid JSON or a non-object root returns both defaults.

Difficulty: intermediate

Examples

  • ["{\"theme\":\"dark\",\"notifications\":false}"]{"theme":"dark","notifications":false}

Your solution

Python

Results

Python starts when you run or submit this challenge.

Back to Lesson