import json # Using readlines() fileslist = open('0-listoffiles.txt', 'r') Lines = fileslist.readlines() fileoutput = open('alllines.txt','a') # Strips the newline character for line in Lines: fileoutput.write(line) with open('mergedjson.json') as jsonfile: data = json.load(jsonfile) for f in data: file = f["debrispath"] fileoutput.write(file+"\n")