This is the code I am using for preprocessing the SQuAD dataset.
passage_word_counts = []
passages_dict = {}
reverse_passage_dict = {}
questions = []
count = 1
for dat in data['data']:
    for idx, para in enumerate(dat['paragraphs']):
        text = para['context'].lower()
        if len(tokenizer(text)['input_ids']) > 512:
            continue
        passage_word_counts.append(len(word_tokenize(text)))
        reverse_passage_dict[text] = count
        passages_dict[count] = text
        for qas in para['qas']:
            question = qas['question'].lower()
            questions.append((question, count))
        count += 1

passage_dict is a dictionary of the format {unique_id: passage} and questions is a list of tuples of the format [(question_1, id_of_the_passage_that_has_answer),(question_2, id_of_the_passage_that_has_answer), ......]. I am removing passages that has more than 512 tokens after tokenization and count is used to assign unique_id to the passages.