Aerostack
bar_chart

data-csv-to-json Edge Function — Data

Data

Converts a CSV string to a typed JSON array, automatically inferring numbers, booleans, and null values from string fields.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function data-csv-to-json Converts a CSV string to a typed JSON array, automatically inferring numbers, booleans, and null values from string fields.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/data-csv-to-json
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "data-csv-to-json",
  args: {
    "csv": "example_csv",
    "delimiter": ",",
    "inferTypes": true
  }
})

data-csv-to-json — CSV to typed JSON array

Converts a CSV string to a typed JSON array, auto-inferring numbers, booleans, and null values.


API

POST /api/data-csv-to-json

Request body

Field Type Required Default Description
csv string The CSV string to convert
delimiter string ',' Field delimiter
inferTypes boolean true Auto-cast numbers, booleans, null

Type inference rules (when inferTypes=true):

  • Empty string → null
  • "true" / "false"boolean
  • Numeric strings → number
  • Everything else → string

Success response (200)

{
  "success": true,
  "data": {
    "data": [{ "name": "Alice", "age": 30, "active": true }],
    "headers": ["name", "age", "active"],
    "rowCount": 1
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 Missing csv field
INTERNAL_ERROR 500 Unexpected error

Usage

cURL
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -d '{"csv": "name,age,active\nAlice,30,true"}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ csv: csvString, inferTypes: true }),
});
const { data } = await response.json();
console.log(data.data);
Direct import (Node / Bun / Deno)
import { csvToJson } from '@aerostack/functions/data-csv-to-json';

const { data, headers } = csvToJson({ csv: myCsvString });

Use Cases

  • Converting spreadsheet exports to JSON before inserting into a database
  • Processing CSV data from third-party integrations (analytics exports, CRM dumps)
  • Feeding CSV data into an AI workflow that expects typed JSON

Notes

  • Type inference applies to the trimmed value — " 30 " becomes 30 (number)
  • Set inferTypes: false to keep all values as strings
  • First row is always treated as the header row

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

data
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More Data Functions

Browse Data Functions →

Frequently asked questions

What does the data-csv-to-json function do? +

data-csv-to-json is a serverless edge function for data automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the data-csv-to-json function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/data-csv-to-json ``` It will be live on Cloudflare Workers in seconds.

What runtime does data-csv-to-json use? +

data-csv-to-json runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the data-csv-to-json function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.