# NDJSON Converter: JSONL to CSV, JSON and Excel (`ucchiii/ndjson-converter`) Actor

Convert NDJSON / JSON Lines to CSV, JSON array or Excel, and CSV, JSON or Apify datasets back to NDJSON. Flattens nested objects, keeps every column, reads .gz, skips broken lines and reports them. Empty input = free demo.

- **URL**: https://apify.com/ucchiii/ndjson-converter.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 $0.02 / 1,000 converted rows

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

**Convert NDJSON / JSON Lines to CSV, JSON or Excel, and CSV, JSON or Apify datasets back to NDJSON, without writing a script**

**For anyone who has a `.ndjson` or `.jsonl` file and needs a spreadsheet, or has a spreadsheet and needs one JSON object per line.** Typical cases: a log export or database dump you want to open in Excel, an Apify dataset you want to load into BigQuery or a streaming tool that expects JSON Lines, an API that returns one JSON object per line. Give this Actor file URLs or a dataset, pick the output format, and get **the converted file plus a public download link**.
**$0.0015 per converted file plus $0.000035 per converted row ($0.035 per 1,000 rows).** Broken lines are skipped and are not charged. **The $5 monthly free credit covers about 130,000 rows in 1,000-row files.** Failed files and the demo are free. No scraping, no API keys.

**Try it free: leave the file list and dataset empty and press Start** (clear the prefilled URL first). The demo converts a built-in NDJSON sample that contains a nested object, a list, a blank line and one broken line. It is not charged and the result row carries `_demo: true`.

### The problems it solves

- **You cannot open a `.jsonl` file in Excel.** Convert it to CSV or `.xlsx`. Nested objects become columns with dotted names (`customer.name`), and the columns are the union of all lines, so a key that only appears in some lines still gets its own column.
- **One bad line breaks your import.** A truncated line from a crashed export, a stray log message or a half-written last line does not stop the file. The bad line is skipped and listed in the result with its line number and the reason, so you can see exactly what was left out.
- **A tool wants JSON Lines and you have a CSV, a JSON array or an Apify dataset.** Convert it to NDJSON (or a `.jsonl` file) in one step. Numbers in a CSV become numbers; values like `01234` stay text so zip codes and IDs are not changed.
- **The file is compressed.** `.gz` files are unzipped automatically.
- **Several files, one run.** Each file gets its own output file and one result row.

### What it does

- **NDJSON / JSONL to CSV, JSON array or Excel (.xlsx).**
  - Nested objects are flattened into dot keys (you can pick another separator).
  - A list inside a line is written as JSON text, or joined with `; ` for lists of words and numbers.
  - Columns are the union across all lines, in the order they first appear.
  - Blank lines are ignored, and a byte-order mark or Windows line endings do not matter.
- **CSV, TSV, JSON array or Apify dataset to NDJSON / JSONL.** A JSON file with one array inside an object (`{"items": [...]}`) is read as that array.
- **NDJSON to cleaned NDJSON.** Choose NDJSON as the output of an NDJSON file to drop the broken lines and blank lines.
- **Reads** UTF-8 (with or without BOM), UTF-16 with BOM, and, as a fallback, Shift_JIS and Windows-1252 text. Output is always UTF-8.
- **Reports** for each file: input and output format, rows, broken lines with details, columns, and whether it was gzip-compressed.

### Input example

```json
{
  "fileUrls": ["https://example.com/exports/events.jsonl.gz"],
  "outputFormat": "xlsx",
  "arrayMode": "join"
}
```

Converting a dataset: use `datasetIds`. Every item of the dataset becomes one row of the output file, which is NDJSON unless you choose another format. If a dataset's items hold `contentBase64` (the file bytes, base64-encoded) and optionally `fileName`, each item is instead read as one file, exactly like a file URL.

### Output

- **Dataset**: one row per source file.
- **Key-value store**: the converted file under `outputKey` (for example `events.xlsx`). `url` is Apify's signed public link, so you can share the file without sharing your token.
- **STATS** record: files converted and failed, rows converted, broken lines skipped and what was charged.

```json
{
  "file": "https://example.com/exports/events.jsonl.gz",
  "from": "ndjson",
  "to": "csv",
  "rows": 2500,
  "badLines": 1,
  "url": "https://api.apify.com/v2/key-value-stores/…/records/events.csv?signature=…",
  "status": "ok",
  "blankLines": 3,
  "badLineDetails": [{"line": 1207, "reason": "Expecting ',' delimiter (column 151)", "text": "{\"id\": 1207, \"user\": {\"name\": \"Ana\", \"vip\": fals"}],
  "encoding": "utf-8", "gzip": true, "columns": 14,
  "inputBytes": 118204, "outputBytes": 231905, "chargedRows": 2500, "chargedFiles": 1, "outputKey": "events.csv"
}
```

`badLineDetails` lists the first 50 broken lines (the count in `badLines` is always complete). Line numbers count every line of the file, including blank lines.

### Limits (cannot be raised by input)

- 50 MB per source file (100 MB after unzipping); 50 files per run (200 MB in total for files read from datasets); at most 500,000 rows per file. A file over a limit fails and is not charged
- A download is tried up to 3 times when the server is slow or answers with a temporary error (HTTP 429, 5xx); a clear error such as 404 is not retried. The timeout is 60 seconds per request
- Source URLs must be public `http` or `https` links. Addresses on internal networks (localhost, private ranges, cloud metadata) are blocked, also after redirects
- Input can be NDJSON / JSONL, JSON, CSV or TSV (optionally gzip-compressed). Excel workbooks and other binary files cannot be read
- A file with more than 1,000 different columns cannot be written as CSV or Excel; use JSON or NDJSON output instead

### Pricing

Pay per event: **$0.0015 per converted file** (event `file`) **plus $0.000035 per converted row** (event `row`). Only rows that were written count: broken lines and blank lines are free. A 1,000-row file costs $0.0365 and a 100,000-row file costs $3.50. A file that fails (download error, no valid line, over a limit) is not charged. Set a maximum charge per run to cap spend; a file that does not fit in the remaining budget is skipped whole, never cut. If none of the files fit, nothing is converted or charged and the run ends as Failed ("No file could be converted. See the dataset rows for the reason."); each skipped file's row in the dataset says "Max charge reached before this file; it was not converted."
On the Apify Free plan, the $5 of monthly platform credit covers about **140,000 rows** a month in large files, enough to try it on real data.

### FAQ

**What is the difference between NDJSON and JSONL?** Nothing in the content: both mean one JSON value per line. The Actor reads both, and lets you choose the file extension of the output.
**What happens to nested lists?** In CSV and Excel they are written as JSON text in one cell, or joined with `; ` if you choose "join" and the list holds only text, numbers or booleans. In JSON and NDJSON output they stay as they are.
**Why are some CSV cells numbers and others text?** When reading CSV, cells like `12` and `3.5` become numbers. Cells with a leading zero, more than 15 digits or an exponent stay text. Turn the option off to keep everything as text.
**Can an Excel file be the input?** No. Export the sheet as CSV first.
**Does it change my source?** No. It only reads the file and writes a new one.
**Is the file link private?** Anyone holding the signed link can download that file; it gives no access to anything else in your account.
**Will formulas in my data run in Excel?** In `.xlsx` output text that starts with `=` is stored as text. For CSV, turn on "neutralize formulas" if the data comes from an untrusted source.

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

### More tools from the same developer

- [CSV to JSON Converter](https://apify.com/ucchiii/csv-to-json) — turn CSV files into typed JSON: encoding and delimiter detected, numbers and booleans typed, dotted headers nested, array, NDJSON or keyed output
- [JSON to CSV Converter](https://apify.com/ucchiii/json-to-csv) — turn nested JSON files or datasets into one flat CSV file
- [Flatten JSON to CSV](https://apify.com/ucchiii/flatten-json) — flatten nested JSON into flat rows with the separator you choose
- [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
- [CSV Encoding Converter](https://apify.com/ucchiii/csv-encoding-converter) — detect the encoding of CSV and text files and convert them to UTF-8 (or another encoding)

# Actor input Schema

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

Public http(s) links to NDJSON / JSONL, CSV, TSV or JSON files, one per entry. Files ending in .gz are unzipped (up to 50 files, 50 MB each, 100 MB after unzipping). Links to internal networks are blocked. Leave this AND 'Apify datasets' empty to run a free demo on a built-in sample (not charged).

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

Optional. Dataset IDs to convert: every item becomes one row of the output file (usually NDJSON). Or, if the items hold 'contentBase64' (the file bytes, base64-encoded) and optionally 'fileName', each item is read as one file like a file URL.

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

Format of the source files. 'auto' uses the file name, the content type and the first line. Choose one yourself if the guess is wrong. Not used for datasets. Default: auto.

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

Format of the converted file. 'auto' turns NDJSON into CSV and turns CSV, JSON and datasets into NDJSON. NDJSON and JSON Lines have the same content; only the file extension differs. Default: auto.

## `arrayMode` (type: `string`):

How a list inside a line is written into a CSV or Excel cell. 'json' keeps it exact; 'join' is easier to read for lists of words or numbers (lists of objects stay JSON). Only used for CSV and Excel output. Default: json.

## `flattenSeparator` (type: `string`):

Joins the names of nested keys into one column name, so {"a": {"b": 1}} becomes the column a.b. Up to 5 characters. Only used for CSV and Excel output. Default: a dot.

## `outputDelimiter` (type: `string`):

Column separator of a CSV output file. Quotes are added only where needed. Default: comma.

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

When reading CSV or TSV, writes cells like 12 or 3.5 as numbers in the JSON output. Values with a leading zero (01234), more than 15 digits or an exponent stay text. Turn off to keep every cell as text. Default: on.

## `csvBom` (type: `boolean`):

Adds a byte-order mark to CSV output so Excel opens non-English text correctly by double-click. Leave off for pandas, databases and most code. Default: off.

## `csvEscapeFormulas` (type: `boolean`):

Puts a ' in front of CSV cells that start with =, +, - or @ so a spreadsheet cannot run them as formulas. Useful when the file comes from untrusted data; it changes those cells. Excel output never runs formulas. Default: off.

## `maxRows` (type: `integer`):

A file or dataset with more rows than this fails and is not charged, so a surprise file cannot run up a bill. Default and upper limit: 500,000.

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

File name without extension for the output; the extension follows the output format and, 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"
  ],
  "inputFormat": "auto",
  "outputFormat": "auto",
  "arrayMode": "json",
  "flattenSeparator": ".",
  "outputDelimiter": ",",
  "inferTypes": true,
  "csvBom": false,
  "csvEscapeFormulas": false,
  "maxRows": 500000
}
```

# Actor output Schema

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

One row per source file: input and output format, rows, broken lines (with line numbers), the download link (url) or the error. Download as CSV, JSON, Excel and more.

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

Record STATS: files converted and failed, rows converted, broken lines skipped and what was charged.

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

The key-value store that holds the converted output 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/ndjson-converter").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/ndjson-converter").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/ndjson-converter --silent --output-dataset

```

## MCP server setup

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

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/b5YsxPyU2zZ6hbMPm/builds/xMuKlqRbZGMdq5URI/openapi.json
