I would like to convert an JSON Array into a CSV file. This is because I want to generate a dataset that I can test using JMeter on my API whether my API is strong enough to handle many requests at the same time.
As soon as I normally import the array into the CSV, the array comes up with a single quotes so that the API does not take it as a valid JSON. When I use json.dumps(array)
then the array will be placed in the CSV file as shown on the right, which is also not correct "[""726102""]"
.
I would like my array: ['726102']
in this way -> ["726102"]
in the CSV file so that I can read it with JMeter
array = ["726102"]
with open('result.csv', 'w', newline='', encoding="utf-8") as file:
fieldnames = ["array"]
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'array': json.dumps(array)})
The result is now:
array
"[""726102""]"
But what I expected it to be:
array
["726102"]