← All posts

Read CSV file from Request Body and turn it into JSON

Jun 26, 20241 min readCloudflare

Let’s say you’ve sent a CSV file in formdata. The key for the CSV file is myCsvFile.

To read the data as JSON, you’ll have to install csvtojson package and do the following,

import csvtojson from "csvtojson"

// your usual code... 

const formdata = await request.formdata() // request is simple request object.
const csvFile = formdata.get('myCsvFile')

const json = await csvtojson().fromString(await csvFile.text())

Yes, it is that simple!

If you’re using cloudflare workers, I found this article very helpful → https://blog.remeika.us/2023/07/07/parsing-csv-files.html

Pranav Malvawala
Pranav MalvawalaCo-founder and CTO of Feather and NotionSender. Writes about tech, startups and money.

Keep reading

Facebook og:image not showing? Your image URL probably redirectsWhy I ditched Turnstile and built rate limiting with Cloudflare KV