# CSV to JSON & JSON to CSV Converter - Batch, JSON Lines (`tidytools/tabular-transformer`) Actor

CSV to JSON and JSON to CSV converter: batch up to 20 pasted CSV, JSON or JSON Lines files per run with Miller; keep, rename and sort columns, download each result. $0.003 per converted file; empty, invalid or too large files are free.

- **URL**: https://apify.com/tidytools/tabular-transformer.md
- **Developed by:** [Yukai Lin](https://apify.com/tidytools) (community)
- **Categories:** Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.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

### What does Tabular Transformer do?

Give it up to **20 CSV, JSON or JSON Lines files** in one run; it converts each one with [Miller](https://github.com/johnkerl/miller) and saves the result as a file you can download: **CSV to JSON, JSON to CSV, JSON Lines to CSV** and every other pair of the three. Along the way it can **keep only some columns, rename columns and sort the rows**.

- **Batch, unattended**: every file gets its own result and its own row, so one bad file never stops the others.
- **Fixed, safe operations**: only select, rename and sort. No scripts, Miller expressions, command-line text or URLs are accepted, so a scheduled run always does exactly what its input says.
- **Faithful values**: numbers are written as in your file (`9.8870` stays `9.8870`); zip codes like `02134` and text like `0xff` stay text. Records with different fields (JSON Lines) become one CSV with empty cells where a field is missing.
- **Clear free rows**: an empty file, a broken CSV, a column name that does not exist or a file over the size limits gets a free row with `errorType` and the reason.

### Use cases

- Turn CSV exports (CRM, shop, analytics) into JSON for an API, a database import or an AI agent, on a schedule.
- Turn JSON or JSON Lines from an API or another Actor into CSV for Excel or Google Sheets.
- Keep only the columns a partner needs, with their names, in the order they expect.
- Sort a list by date, amount or name before sending it on.

### How much does it cost?

**$0.003 per converted file** (event `file-transformed`; Silver plan $0.0027, Gold and above $0.0024). No start fee.

- A file is charged once, after its result is saved in the key-value store and its row is saved in the dataset.
- A file that converts correctly but has **0 rows** (for example a CSV with only a header line) is a completed conversion and is charged.
- **Free (not charged)**: empty files, files that are not valid CSV / JSON / JSON Lines, column names that do not exist, files over the size limits, files after the 20th, conversions that time out, results that could not be saved, and files left when your maximum charge per run is reached (`errorType: charge_limit`).
- If the run restarts (an Apify server migration), files that already have a row are not converted or charged again.
- The converted file is not necessarily smaller than the input: CSV to JSON usually makes it bigger.

### How to use it

1. Put your files in **Files**: `[{"name": "sales.csv", "dataText": "<the file's text>"}]`, up to 20 per run.
2. Choose the **Input format** (all files of a run have the same format) and the **Output format**.
3. Optionally list **Keep only these columns**, **Rename columns** and **Sort rows by**.
4. Run. Open the **Files (overview)** view: each converted file has a download link (`outputUrl`) to its record in the run's key-value store (`outputKey`).

#### Limits

| Limit | Value |
|---|---|
| Files per run | 1 to 20 (more files get a free row each) |
| One file | 256 KB of UTF-8 text |
| All files of a run | 1 MB together (files past it get a free `too_large` row) |
| One converted file | 4 MB (a bigger result is a free `output_too_large` row) |
| Time per file | 20 seconds per Miller step (longer is a free `timeout` row) |
| Keep only these columns | up to 50 names |
| Rename columns | up to 50 pairs |
| Sort rows by | up to 3 columns, `asc` or `desc` |

Column names are case sensitive and must exist in the file (sort and rename use the names as they are in the file). Names containing a comma or a line break cannot be used in these options. A rename may not give a column the name of another column, and a renamed column must be among the kept columns when you keep only some. A column whose values are all numbers sorts as numbers; other columns sort as text.

#### Input example (Miller's official example.csv, first two records)

```json
{
    "files": [
        {
            "name": "example.csv",
            "dataText": "color,shape,flag,k,index,quantity,rate\nyellow,triangle,true,1,11,43.6498,9.8870\nred,square,true,2,15,79.2778,0.0130\n"
        }
    ],
    "inputFormat": "csv",
    "outputFormat": "csv",
    "selectColumns": ["color", "shape"]
}
```

The key-value store record `OUTPUT-01-example.csv` then holds:

```
color,shape
yellow,triangle
red,square
```

#### Output example (one converted file and the free row of an empty file)

```json
[
    {
        "inputIndex": 0,
        "name": "example.csv",
        "outputKey": "OUTPUT-01-example.csv",
        "outputUrl": "https://api.apify.com/v2/key-value-stores/<store id>/records/OUTPUT-01-example.csv",
        "inputBytes": 116,
        "outputBytes": 39,
        "recordCount": 2,
        "success": true,
        "charged": true,
        "errorType": null
    },
    {
        "inputIndex": 1,
        "name": "empty.csv",
        "outputKey": null,
        "inputBytes": 0,
        "outputBytes": null,
        "recordCount": null,
        "success": false,
        "charged": false,
        "errorType": "invalid_input",
        "error": "the file is empty (not charged)"
    }
]
```

| Field | Meaning |
|---|---|
| `inputIndex`, `name` | position (from 0) and name of the input file |
| `outputKey`, `outputUrl` | key-value store record of the converted file (`OUTPUT-<nn>-<name>.<format>`) and its download link |
| `inputBytes`, `outputBytes` | size of the input text and of the converted file, in UTF-8 bytes |
| `recordCount` | data rows (records) in the converted file; 0 is possible |
| `success`, `charged` | `true` for a converted file. `charged: true` means the charge is sent: it is written when the row is stored, just before the one charge for that file (a stored row cannot be changed afterwards). In the rare case that the charge does not go through, SUMMARY lists the file's `inputIndex`: in `notCharged` when Apify answered without charging it (the file is free), in `chargeUnknown` when the charge request itself failed, for example timed out, so Apify may or may not have recorded it. The charge is never sent again, so a file is charged at most once; SUMMARY `billing` and the run's charged events in Apify Console show what was actually charged |
| `errorType`, `error` | why a file was not converted (free rows only): `invalid_input`, `too_large`, `output_too_large`, `timeout`, `save_failed`, `charge_limit`, `service_unavailable`, `failed` |

The run's **SUMMARY** record counts converted files (`succeeded`), free rows (`freeFailures`, by `errorTypes`) and files whose charge Apify confirmed (`chargedFiles`, `events.file-transformed`; converted files whose charge did not go through are left out and listed in `notCharged` or `chargeUnknown`, see `charged` above), lists the output records (`outputKeys`), the Miller version and the time per file, and adds a `billing` block with what Apify actually charged.

### Use it from code

```bash
curl -X POST "https://api.apify.com/v2/acts/tidytools~tabular-transformer/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"files": [{"name": "people.jsonl", "dataText": "{\"id\": 1, \"name\": \"Ada\"}\n{\"id\": 2, \"name\": \"Bob\", \"team\": \"red\"}\n"}], "inputFormat": "jsonl", "outputFormat": "csv"}'
```

Then download each row's `outputUrl`.

### Limitations

- Text input only (`dataText`); no file links or uploads in this version. Excel files must be saved as CSV first.
- CSV means comma-separated with a header line. Rows with a different number of fields than the header, or an unclosed quote, make the file invalid (free row).
- All files of a run share one input format and one set of options.
- JSON output keeps nested objects; CSV output flattens them into columns such as `address.city`.

### FAQ

**Can I run my own Miller command or expression?** No. Only the three operations above are available, on purpose: a scheduled run cannot be turned into something else by its input.

**Why did a file get `invalid_input`?** It is empty, not valid in the chosen input format, or an option names a column it does not have. The `error` says which, and for a missing column it lists the file's columns.

**Does the Actor collect usage data?** It sends one anonymous usage counter per run (input type, item count range, outcome) to improve the tool; no file names, content or account data.

### Third-party software

This Actor runs Miller 6.22.0 (`mlr`), unmodified, under its BSD 2-Clause license; the license file is included in the Actor's image at `/usr/share/licenses/miller/`.

> Copyright (c) 2015- John Kerl. All rights reserved.
>
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
>
> - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
> - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
>
> This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright holder or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

### Support

Open an issue in the **Issues** tab with a small sample of the file and the options you used. Issues are checked regularly.

# Actor input Schema

## `files` (type: `array`):

1 to 20 files, each {"name": "sales.csv", "dataText": "\<the file's text>"}. All files of a run have the same format (Input format). At most 256 KB of UTF-8 text per file and 1 MB per run; empty files, files over the limits and files after the 20th get a free row.

## `inputFormat` (type: `string`):

Format of every file: CSV with a header line, a JSON array of objects (or one object per file), or JSON Lines (one object per line).

## `outputFormat` (type: `string`):

Format of the converted files. CSV output fills fields missing in some records with empty values and writes nested JSON fields as flattened columns (a.b).

## `selectColumns` (type: `array`):

Up to 50 column names, in the order you want them. Empty = all columns. Names are case sensitive and must exist in the file, otherwise the file gets a free invalid_input row listing its columns.

## `renameColumns` (type: `array`):

Up to 50 pairs: key = the column's name in the file, value = the new name. The new name may not be another column's name.

## `sortBy` (type: `array`):

Up to 3 columns, e.g. \[{"column": "quantity", "direction": "desc"}, {"column": "color", "direction": "asc"}]. Columns whose values are all numbers sort as numbers, others as text (case sensitive). Uses the names in the file, before renaming.

## Actor input object example

```json
{
  "files": [
    {
      "name": "example.csv",
      "dataText": "color,shape,flag,k,index,quantity,rate\nyellow,triangle,true,1,11,43.6498,9.8870\nred,square,true,2,15,79.2778,0.0130\n"
    }
  ],
  "inputFormat": "csv",
  "outputFormat": "csv"
}
```

# Actor output Schema

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

No description

## `outputs` (type: `string`):

No description

## `summary` (type: `string`):

No description

# 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 = {
    "files": [
        {
            "name": "example.csv",
            "dataText": "color,shape,flag,k,index,quantity,rate\nyellow,triangle,true,1,11,43.6498,9.8870\nred,square,true,2,15,79.2778,0.0130\n"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("tidytools/tabular-transformer").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 = { "files": [{
            "name": "example.csv",
            "dataText": """color,shape,flag,k,index,quantity,rate
yellow,triangle,true,1,11,43.6498,9.8870
red,square,true,2,15,79.2778,0.0130
""",
        }] }

# Run the Actor and wait for it to finish
run = client.actor("tidytools/tabular-transformer").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 '{
  "files": [
    {
      "name": "example.csv",
      "dataText": "color,shape,flag,k,index,quantity,rate\\nyellow,triangle,true,1,11,43.6498,9.8870\\nred,square,true,2,15,79.2778,0.0130\\n"
    }
  ]
}' |
apify call tidytools/tabular-transformer --silent --output-dataset

```

## MCP server setup

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

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/yCPXHdvZWvIgO7HEl/builds/g6zgWw8FCMSwgueGr/openapi.json
