from jsonschema import validate from json import dumps, loads class PalleteSchema : colors = None schema = { "type" : "array", "items" : { "type" : "object", "properties" : { "name" : { "type" : "string" }, "color" : { "type" : "array", "items" : { "type" : "number" } } }, "required" : [ "name", "color" ] } } def __init__ (self, file = None): if file is not None: self.parse_file(file) def parse_file (self, file) : with open(file) as f : self.parse(f.read()) print(f'Parsed pallete file {file}') def parse (self, jsonstr) : obj = loads(jsonstr) validate( instance = obj, schema = self.schema) self.colors = obj