Create an API endpoint to convert a CSV file into JSON


In this tutorial, you’ll learn how to create a API endpoint that converts a CSV to JSON.

Specifically, you’ll learn how to:

  • Read a CSV file URL from a website
  • Convert the CSV file to JSON format
  • Create the API endpoint that returns the resulting JSON

When you’re done, you’ll be able call the API endpoint to read a CSV file on the web and return it as JSON.


To complete this tutorial, you’ll need:

Read a CSV file from a website

To begin, you’ll create a basic pipe that reads a CSV located at a URL.

  1. Create a new pipe in

  2. By default, you’ll see a sample Execute Task, which will house our function. In the drop-down menu, change the language to “Node.js”. Then, paste the following code into the Execute Task and Save Changes:

  1. After saving your changes, press the “TEST” button in the upper right of the Pipe Builder. You should see the CSV data parsed into a JSON format, similar to the following:

Convert the CSV file to JSON format

Now that you have read your CSV data, you’ll need to get it into JSON format, as follows:

  1. You’ll now edit your current Execute Task with the conversion code.

  2. First, add const parse = require('csv-parse/lib/sync') under const axios = require('axios')

  3. Then, update the logic inside the .then(response => {}) to the following:

When you’re done, your full code block should look like this:

  1. After saving your changes, press the “TEST” button again. You should now see data transformed, similar to the following:

Set up an API endpoint to access the data

Next, you’ll simply need to get an API endpoint to access this data transformation feed you just created, as follows:

  1. First, turn on your pipe to activate it.

  2. Then, scroll down to the Deployment section and check the box next to Run using an API endpoint to see your API endpoint and API key.

  3. Next to the endpoint, which by default uses the unique pipe EID as a reference, click the Edit button to add an alias to your pipe as follows: example-create-an-api-endpoint-to-convert-a-csv-file-to-json.

  4. To quickly test the endpoint, copy the HTTPS endpoint and paste it into your browser to see your data; the HTTPS endpoint will look like this (where {token} is your unique API key):{token}

Going further

Of course, now that you have your endpoint, you’re now ready to invoke it in any server or client code that allows you to make an HTTP request. Here are two examples.

HTML Script:

<script src=""></script>
method: 'post',
url: '',
headers: {
Authorization: 'Bearer {token}'
.then(response => {
// var converted_data =
.catch(response => {


curl -X POST ''
--header "Authorization: Bearer {token}"