From 2b2a6ddd25f0957e964a4786612da1c5374d6531 Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Wed, 22 Jun 2022 01:57:03 +0100 Subject: [PATCH] Updated json structure validation Only works with the data list File parsed in the View layer --- ref-test/app/tools/data.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ref-test/app/tools/data.py b/ref-test/app/tools/data.py index 778c05a..7eab4d9 100644 --- a/ref-test/app/tools/data.py +++ b/ref-test/app/tools/data.py @@ -18,12 +18,10 @@ def check_is_json(file): if not '.' in file.filename or not file.filename.rsplit('.',1)[-1] == 'json': return False return True -def validate_json(file): - file.stream.seek(0) - data = json.loads(file.read()) +def validate_json(data): if not isinstance(data, list): return False for block in data: - block_type = block.pop('type', None) + block_type = block.get('type', None) if block_type not in ['block', 'question']: return False if block_type == 'question': if not all (key in block for key in ['q_no', 'text', 'options', 'correct', 'q_type', 'tags']): return False