# CSV to JSON Converter: nested, typed, any shape (`ucchiii/csv-to-json`) Actor

Convert CSV files to JSON: detects encoding (Shift_JIS, UTF-8, Windows-1252) and delimiter, types numbers/booleans/null, nests dotted headers, writes arrays, NDJSON or keyed objects. Empty input = free demo.

- **URL**: https://apify.com/ucchiii/csv-to-json.md
- **Developed by:** [Actor Factory](https://apify.com/ucchiii) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.40 / 1,000 converted files

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

**CSV to JSON converter: typed values, nested objects from dotted headers, and the JSON shape you need. Encoding and delimiter are detected for you.**

- **Cost:** $0.002 per converted file, whatever its row count (up to 100,000 rows). **The $5 monthly free credit covers about 2,500 files.** Failed files and the demo are free.
- **Output:** one `.json` (or `.ndjson`) file per CSV with a download link, plus one result row per file.

**For anyone who has a CSV and needs JSON that code can use straight away.** Most converters give you every value as text and leave you to fix the numbers, the empty cells and the garbled Japanese, Chinese or accented characters. This Actor reads the file the way a person would: it finds the encoding and the delimiter itself, turns `12800` into a number, `true` into a boolean and an empty cell into `null`, and keeps dates and ID codes as text. You get a file you can load into a script, an API, a database or a JavaScript app without a cleaning step.

**Try it free:** leave every input empty and press **Start** (clear the prefilled URL first). A built-in Shift_JIS sample is converted, nothing is charged, and the result row carries `_demo: true`.

### The problems it solves

- **A CSV from a Japanese, Chinese or European system shows broken characters when you convert it.** The encoding is detected (UTF-8, UTF-8 with BOM, Shift_JIS, EUC-JP, GBK, Big5, EUC-KR, Windows-1252, Windows-1251 and more) and the JSON is always clean UTF-8. The result row says what was found and how sure it is.
- **Semicolon, tab or pipe separated exports.** The delimiter is detected, or you choose it.
- **Everything arrives as text.** Numbers, `true`/`false` and empty cells get real JSON types, column by column, so one stray `N/A` never turns half a column into numbers.
- **Flat headers, nested data needed.** Turn on **Nest dotted headers** and `address.city` becomes `{"address": {"city": ...}}`.
- **You need a lookup table or a loader format, not a list.** Choose the output shape: array of objects, NDJSON (one object per line), an object keyed by a column you pick, or one array per column.
- **European number formats.** Choose the decimal comma and `1.234,56` becomes `1234.56`.

### What you get

Input CSV:

```csv
id,name,address.city,total,paid,joined,zip
1,Ann,Tokyo,12800,true,2026-04-01,0150001
2,Bob,,5400.5,false,2026-04-03,5300001
```

With **Nest dotted headers** on, the JSON file holds:

```json
[
  {"id": 1, "name": "Ann", "address": {"city": "Tokyo"}, "total": 12800, "paid": true, "joined": "2026-04-01", "zip": "0150001"},
  {"id": 2, "name": "Bob", "address": {"city": null}, "total": 5400.5, "paid": false, "joined": "2026-04-03", "zip": "5300001"}
]
```

The other shapes of the same data:

| Output shape | Looks like |
|---|---|
| Array of objects (default) | `[{"id": 1, ...}, {"id": 2, ...}]` |
| NDJSON / JSON Lines | one `{"id": 1, ...}` object per line |
| Keyed by a column (`keyColumn: "id"`) | `{"1": {"id": 1, ...}, "2": {"id": 2, ...}}` |
| Columns as arrays | `{"id": [1, 2], "name": ["Ann", "Bob"], ...}` |

### How to use

1. **File URLs**: public links to CSV or TSV files, one per line (up to 50). **Or** a key-value store with CSV records, **or** datasets whose items hold `contentBase64` and an optional `fileName` (useful after another step produced the file).
2. Pick the **Output shape**. Everything else has a sensible default.
3. Press **Start**. Each file becomes one JSON file in the run's key-value store; open the **Converted files** table for the download links.

```json
{
  "fileUrls": ["https://example.com/exports/orders.csv"],
  "outputShape": "array",
  "nestDottedHeaders": true,
  "stringColumns": ["zip"],
  "prettyPrint": false
}
```

### Options

- **Detect numbers, true/false and null** (on by default). A column becomes numbers only when every filled cell is a number, and booleans only when every filled cell is `true` or `false` (any case). Empty cells and the word `null` become `null`. Everything else stays text: dates and timestamps (ISO dates are never converted), codes with leading zeros (`007`, `09012345678`) and numbers longer than 15 digits.
- **Always keep as text**: list the headers of columns that must stay text even if they look like numbers.
- **Decimal separator**: point (`1234.56`) or comma (`1.234,56`).
- **Nest dotted headers** (off by default, so headers such as `v1.2` are safe). If a file has both `address` and `address.city`, it fails with a clear message instead of guessing.
- **Leave out empty values**: skip keys whose value is `null`.
- **First row is a header**: turn off to get `column_1`, `column_2`... Empty and repeated headers get `column_N` and `name_2` names, and rows with too few or too many cells are padded and counted as `raggedRows`.
- **Input encoding**: detection is a best guess (the confidence is a rough guide). If the result looks garbled, set it yourself, for example `cp1250` for Central European text or `koi8_r` for old Russian files.
- **Trim spaces**, **Input delimiter**, **Input encoding**, **Indent the JSON**, **Output file name**.
- **Also write the rows to the dataset**: the first 10,000 rows of each file (50,000 per run) are also saved as dataset items with `_source` and `_row`, so you can download or process them as an Apify dataset. The JSON file always holds every row. No extra charge.

### Output

- **Key-value store**: the converted file under `outputKey` (for example `orders.json`). `outputUrl` is Apify's signed public link, so you can share the file without sharing your token.
- **Dataset**: one result row per file with `source`, `status`, `rows`, `columns`, `delimiter`, `encoding`, `encodingMethod`, `encodingConfidence`, `outputShape`, `columnNames`, `columnTypes`, `preview` (the first two rows), `outputBytes`, `outputUrl` and `error`. Items with `_row` are data rows from the option above.
- **STATS** record: files converted and failed, rows converted and files charged.

```json
{
  "recordType": "file",
  "source": "https://example.com/exports/orders.csv",
  "status": "ok",
  "file": "orders.json",
  "rows": 250,
  "columns": 3,
  "delimiter": "comma",
  "encoding": "shift_jis",
  "encodingMethod": "statistical",
  "encodingConfidence": 0.97,
  "outputShape": "array",
  "columnTypes": {"id": "integer", "customer.name": "string", "total": "integer"},
  "outputUrl": "https://api.apify.com/v2/key-value-stores/.../records/orders.json?signature=..."
}
```

### Limits (cannot be raised by input)

- Up to **50 files** per run, **15 MB** and **100,000 data rows** per file, 1,000 columns. A file over a limit fails for free; split it and run again.
- Public files only, no login. Links to internal network addresses are blocked. Records of a key-value store are read as UTF-8 when they are stored as text; store files in another encoding as binary records.
- If the maximum cost per run you set is lower than the number of files, the run stops cleanly (status Succeeded) after the files that fit; the status message and STATS (`stoppedAtChargeLimit: true`) say so.

### Pricing

Pay per event: **$0.002 per converted file** ($2 per 1,000 files), whatever the number of rows, no start fee. Failed files, files over a limit and the demo are free.
Store discounts apply automatically: BRONZE -10%, SILVER -20%, GOLD -30%.
On the Apify Free plan, the $5 of monthly platform credit covers about 2,500 files a month.

### FAQ

**Is a date converted to a date object?** No. JSON has no date type, so `2026-04-01` stays the string `"2026-04-01"`, exactly as written.

**Why did my ID column stay text?** Values with a leading zero (`0150001`), numbers longer than 15 digits and any column with a non-numeric cell are kept as written, so no digit is ever lost. Use **Always keep as text** to force other columns.

**The characters are wrong.** Check `encoding` and `encodingConfidence` in the result row. If the guess is wrong, choose the **Input encoding** yourself.

**Does it change my values?** Only their type. Text is not rewritten, numbers are not rounded, and the original file is never touched.

**I need the reverse direction.** Use JSON to CSV from the same developer.

If this Actor saved you time, a rating on the Store helps others find it.

### More tools from the same developer

- [JSON to CSV Converter](https://apify.com/ucchiii/json-to-csv) — turn nested JSON files or datasets into one flat CSV file
- [CSV to Excel Converter](https://apify.com/ucchiii/csv-xlsx-converter) — convert CSV, TSV, Excel XLSX, JSON and NDJSON files or Apify datasets into each other
- [Excel to JSON](https://apify.com/ucchiii/excel-to-json) — turn Excel (XLSX) sheets into JSON rows, or a JSON file into an Excel sheet
- [Flatten JSON to CSV](https://apify.com/ucchiii/flatten-json) — flatten nested JSON into flat rows with the separator you choose

# Actor input Schema

## `fileUrls` (type: `array`):

Public http(s) links to CSV, TSV or other delimited text files, one per entry (up to 50 files, 15 MB and 100,000 rows each). Links to internal networks are blocked. Leave this and the other file inputs empty to run a free demo on a built-in sample (not charged).

## `keyValueStoreId` (type: `string`):

Optional. ID or name of a key-value store that holds your CSV files as records (for example files you uploaded in Apify Console or saved with another Actor). Converted in addition to the URLs. Text records are read as UTF-8; store files in another encoding as binary records.

## `keyValueStoreKeys` (type: `array`):

Optional. Keys of the records to convert from the key-value store above, for example 'orders.csv'. Leave empty to convert every record in the store except INPUT, up to 50.

## `datasetIds` (type: `array`):

Optional. Dataset IDs whose items each hold one file: 'contentBase64' (the file bytes, base64-encoded) and optionally 'fileName'. Use this when an earlier step produced the file content. Each item becomes one output file.

## `outputShape` (type: `string`):

Layout of the JSON file. 'array' is the usual list of row objects. 'ndjson' writes one object per line (good for big files and loaders). 'keyed' needs 'Key column' and gives an object keyed by that column's values, which must be unique. 'columns' gives one array per column. Default: array.

## `keyColumn` (type: `string`):

Only for the 'keyed' shape: the header of the column whose values become the keys, for example 'id'. Values must be filled and unique, otherwise the file fails (nothing charged). The key stays inside each object too.

## `inferTypes` (type: `boolean`):

On: a column where every filled cell is a number becomes JSON numbers, every cell true/false becomes booleans, empty cells and the word null become null. Anything else stays text, including dates (2026-04-01 stays a string), leading-zero codes (007, 09012345678) and numbers longer than 15 digits. Off: every cell is text, empty cells are null. Default: on.

## `stringColumns` (type: `array`):

Optional. Headers of columns that must stay text even when they look like numbers, for example 'zip' or 'sku'. Matches the header exactly.

## `decimalSeparator` (type: `string`):

How numbers are written in the file. Choose comma for files from European Excel, where 12,50 means 12.5 (usually semicolon-delimited). Only used when number detection is on. Default: point.

## `nestDottedHeaders` (type: `boolean`):

On: a header like 'address.city' becomes {"address": {"city": ...}}. If one header is both a value and the start of another ('address' and 'address.city'), the file fails with a message naming them. Off: the header stays as written. Default: off.

## `omitNulls` (type: `boolean`):

On: keys whose value is null (empty cell) are left out of each object. Off: they are written as null so every object has the same keys. Does not apply to the 'columns' shape. Default: off.

## `hasHeader` (type: `boolean`):

On: the first row gives the key names. Off: the keys are column_1, column_2 and so on, and every row is data. Default: on.

## `trimCells` (type: `boolean`):

Removes spaces at the start and end of every cell and header. Default: on.

## `inputDelimiter` (type: `string`):

Column separator of the CSV files. 'auto' looks at the first lines and chooses between comma, semicolon, tab and pipe. Default: auto.

## `sourceEncoding` (type: `string`):

Text encoding of the CSV files. 'auto' checks the byte-order mark, then whether the file is valid UTF-8, then a statistical detector (Shift_JIS, Windows-1252 and others); the result row shows what was found and how sure it is. Choose one yourself if the guess is wrong. The JSON output is always UTF-8. Default: auto.

## `prettyPrint` (type: `boolean`):

On: the JSON file is indented for reading and is larger. Off: compact. Has no effect on NDJSON, which is always one compact object per line. Default: off.

## `pushRowsToDataset` (type: `boolean`):

On: the first 10,000 rows of each file (50,000 per run) are also written to the run's dataset as separate items, each with '\_source' and '\_row', so you can use or download them there. The JSON file always holds every row. No extra charge. Default: off.

## `fileName` (type: `string`):

File name without extension for the output (name.json; with several sources a number is added). Only letters, digits, dot, dash and underscore are kept. Empty = derived from each source name.

## Actor input object example

```json
{
  "fileUrls": [
    "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
  ],
  "outputShape": "array",
  "inferTypes": true,
  "decimalSeparator": ".",
  "nestDottedHeaders": false,
  "omitNulls": false,
  "hasHeader": true,
  "trimCells": true,
  "inputDelimiter": "auto",
  "sourceEncoding": "auto",
  "prettyPrint": false,
  "pushRowsToDataset": false
}
```

# Actor output Schema

## `results` (type: `string`):

One row per source file: rows, columns, delimiter, detected encoding, the JSON file key and its public URL (outputUrl), or the error. Download as CSV, JSON, Excel and more.

## `stats` (type: `string`):

Record STATS: files converted and failed, rows converted and files charged.

## `files` (type: `string`):

The key-value store that holds the converted JSON files.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "fileUrls": [
        "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("ucchiii/csv-to-json").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "fileUrls": ["https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"] }

# Run the Actor and wait for it to finish
run = client.actor("ucchiii/csv-to-json").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "fileUrls": [
    "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
  ]
}' |
apify call ucchiii/csv-to-json --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ucchiii/csv-to-json"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/7qwyjjjtgBZK9AFSc/builds/LmGlrEwVIT9evfTEX/openapi.json
