def validate_textbooks_json(text):
 try:
  textbooks = json.loads(text)
 except ValueError:
  raise TextbookValidationError('invalid JSON')
 if (not isinstance(textbooks, (list, tuple))):
  raise TextbookValidationError('must be JSON list')
 for textbook in textbooks:
  validate_textbook_json(textbook)
 all_ids = [textbook['id'] for textbook in textbooks if ('id' in textbook)]
 unique_ids = set(all_ids)
 if (len(all_ids) > len(unique_ids)):
  raise TextbookValidationError('IDs must be unique')
 return textbooks

def validate_textbooks_json ( text ) : try : textbooks = json . loads ( text ) except ValueError : raise TextbookValidationError ( 'invalid JSON' ) if ( not isinstance ( textbooks , ( list , tuple ) ) ) : raise TextbookValidationError ( 'must be JSON list' ) for textbook in textbooks : validate_textbook_json ( textbook ) all_ids = [ textbook [ 'id' ] for textbook in textbooks if ( 'id' in textbook ) ] unique_ids = set ( all_ids ) if ( len ( all_ids ) > len ( unique_ids ) ) : raise TextbookValidationError ( 'IDs must be unique' ) return textbooks
validate the given text as representing a single pdf textbook .