for my university project i have to collect some data from github using the API. I save the result of my api call into a json file and after that i have to convert the json file into a csv file.
i use the following code to conver the json file to a csv:
with open ("data.json", "r") as f:
data = json.load(f)
with open('data.csv', 'w') as f:
fieldnames = data[0].keys()
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for res in range(len(data)):
writer.writerow(data[res])
My problem is that in the json file i have some key/value pair as i follow:
"title" : "Hello \n World"
The "\n" is taken as newline i think because it will split the row of my csv file. How solve this problem? Anyway to make my code to ignore the "\n"?