---
url: https://findutils.com/guides/ndjson-to-csv
title: "Convert NDJSON or JSONL to CSV in Your Browser: Flatten JSON Lines into Rows"
description: "Convert NDJSON and JSONL files to CSV. Read how the union header is built, what Flatten does to nested keys, and what happens to a bad line."
category: converters
content_type: guide
guide_type: subtopic
cluster: data-conversion
locale: en
read_time: 9
status: published
author: "olgunozoktas"
published_at: 2026-09-09T09:00:00Z
excerpt: "Paste the log lines and get a spreadsheet. Read how the union header works, how user.name and tags[0] columns appear, and why one bad line never stops the other rows."
tag_ids: ["ndjson", "jsonl", "json", "csv", "data-conversion"]
tags: ["NDJSON", "JSONL", "JSON", "CSV", "Data Conversion"]
primary_keyword: "ndjson to csv"
secondary_keywords: ["jsonl to csv", "json lines to csv", "convert ndjson to csv", "ndjson to excel", "jsonl to excel", "api logs to csv"]
tool_tag: "ndjson-to-csv"
related_tool: "ndjson-to-csv"
related_tools: ["ndjson-to-csv", "csv-to-ndjson", "json-to-csv", "csv-viewer", "csv-to-excel"]
og_image: "/images/content/guides/ndjson-to-csv-cover-20260909.webp"
image_alt: "A long paper tape of stamped tokens unspools across a workbench and settles into a neat grid of aligned card tiles."
updated_at: "2026-09-09T09:57:48Z"
---

Convert an NDJSON or JSONL file to CSV when you need JSON Lines as spreadsheet rows. FindUtils [NDJSON to CSV](/convert/ndjson-to-csv/) reads one JSON object per line in your browser and writes one CSV row per line. The tool does not upload or store the file. This guide explains where JSON Lines comes from, how the header is built, what the two nested modes do, and how a bad line is reported.

## Why Convert NDJSON to CSV?

NDJSON is also called JSON Lines or JSONL. Each line holds one complete JSON document, and the file as a whole is not one JSON document. That shape is easy to append to and easy to stream. It is hard to read in a spreadsheet, because a spreadsheet wants columns.

- **API log dumps:** one request or one event per line, written as it happens.
- **Streaming exports:** a long export that a writer appends to, line by line.
- **Search-index dumps:** one document or one hit per line from a search cluster.
- **Fine-tune datasets:** machine-learning training files are commonly distributed as `.jsonl`.

A JSON array converter cannot read this format. It parses the whole text as one document, and JSON Lines has no opening bracket and no commas between records. The parse stops at the end of the first line and reports a syntax error. This tool parses every line on its own, which is the only reading that matches the format.

## How to Convert NDJSON to CSV Online

### Step 1: Get the JSON Lines File

Save the log dump, the streaming export, or the search results your service writes. To turn an existing JSON array into lines first, run `jq -c '.[]' data.json > data.ndjson`.

### Step 2: Load the Text

Open FindUtils [NDJSON to CSV](/convert/ndjson-to-csv/). Upload a `.ndjson`, `.jsonl`, `.json` or `.txt` file, paste the text, or drop the file on the page. The conversion runs as soon as the text arrives. Blank lines are skipped and are not errors, a leading byte order mark is dropped, and LF and CRLF line ends both work.

### Step 3: Choose How Nested Values Are Written

**Flatten** is the default. A nested object becomes dot-path columns, and an array becomes indexed columns. **JSON cell** keeps each nested value as JSON text in one cell.

### Step 4: Check the Counts and Download

The status line reports rows, columns and skipped lines. The notes name up to twenty skipped lines by number. Read them first. Then download the CSV or copy it. Turn on **Excel BOM** before the download when the file will open in Excel on Windows.

## How the Header Is Built

The header is the union of every key across every row. The order is first-seen order: a key takes its position from the first row that holds it.

- A key a row does not have becomes an empty cell. A `null` value becomes an empty cell too, so the CSV does not tell the two apart.
- Numbers and booleans are written as text: `1.5` and `true`. Quoting follows RFC 4180, so a cell is quoted only when it holds the delimiter, a double quote, or a line break, and an inner quote is doubled.

## Flatten or JSON Cell

Take these two log lines.

```json
{"ts":"2026-09-09T09:12:04Z","level":"info","user":{"id":41,"name":"Ada"},"tags":["auth","web"],"ms":12}
{"ts":"2026-09-09T09:12:07Z","level":"error","user":{"id":41,"name":"Ada"},"tags":["auth"],"ms":481,"error":"timeout"}
```

**Flatten** writes this CSV:

```text
ts,level,user.id,user.name,tags[0],tags[1],ms,error
2026-09-09T09:12:04Z,info,41,Ada,auth,web,12,
2026-09-09T09:12:07Z,error,41,Ada,auth,,481,timeout
```

Read the two empty cells. The second row has no `tags[1]`, and the first row has no `error`. The column still exists for the row that has the key. An empty object `{}` or an empty array `[]` holds no leaf value, so it produces no column at all.

**JSON cell** writes this CSV instead:

```text
ts,level,user,tags,ms,error
2026-09-09T09:12:04Z,info,"{""id"":41,""name"":""Ada""}","[""auth"",""web""]",12,
2026-09-09T09:12:07Z,error,"{""id"":41,""name"":""Ada""}","[""auth""]",481,timeout
```

The `user` and `tags` cells hold JSON text. Each cell is quoted and each inner quote is doubled, so a reader restores the original text. Use Flatten when you want to sort or filter on `user.name`. Use JSON cell when you want to keep a record whole. The dot path and the `tags[0]` form are the form that JSON flatten tools commonly use, so an unflatten step can rebuild the nested object later.

## What a Bad Line Does

One bad line never stops the conversion. The line is skipped, counted, and named.

- A line that is not valid JSON is reported as `Line N: invalid JSON`.
- A line that is JSON but not an object is reported as `Line N: expected a JSON object`. A number, a string, an array and `null` all fall in this group.

`N` is the line number in the file. It counts from 1, it counts blank lines, and it matches the line your editor shows. Every other line still converts, so a dump with three damaged lines still gives you the rest. The conversion stops only when no line holds a JSON object at all.

## A JSON Array Is Refused

A text that starts with `[` and parses as a JSON array is refused. The message reads: "This is a JSON array, not JSON Lines. Use JSON to CSV for an array of objects." A link to [JSON to CSV](/convert/json-to-csv/) appears under the error. That tool is the right one for an array of objects.

## Output Options and Limits

- **Delimiter and header row:** the delimiter is a comma by default. Choose semicolon for an Excel that expects it, or tab for a paste into a grid. The header row is on by default. Turn it off when the rows go into a file that already has a header.
- **Excel BOM:** adds a UTF-8 byte order mark to the download only. The output on screen does not change.

The input cap is 10 MB, which is 10,000,000 characters. Warning: a very large paste can make the browser tab busy for a moment, because the whole conversion runs on your machine. Use **Download** rather than **Copy** for a big output. The download name is the file stem plus `.csv` when you uploaded or dropped a file, and `ndjson-export.csv` when you pasted the text. Nothing is uploaded, and you can confirm that in the browser's network panel while you convert.

## Practical Examples

### Example 1: API Logs in a Spreadsheet

Save one day of request logs as `.ndjson` and convert with Flatten. Sort by the duration column, filter the level column for errors, and count errors per endpoint with a pivot table.

### Example 2: A Search-Index Dump

A dump from Elasticsearch or OpenSearch writes one hit per line. A hit usually carries an `_id` and a `_source` object. Flatten turns each field under `_source` into its own `_source.` column, so the document body becomes readable columns beside the id.

### Example 3: Checking a Fine-Tune Dataset

A `.jsonl` training file is hard to review in a text editor. Convert it and open the CSV in [CSV Viewer](/convert/csv-viewer/). Sort by a column to find empty values, duplicated records, or rows that lost a field.

## Common Mistakes

### Mistake 1: Pasting a JSON Array

A text that starts with `[` is an array, not JSON Lines. The tool refuses it and points at [JSON to CSV](/convert/json-to-csv/). Use that tool, or split the array into lines first.

### Mistake 2: Expecting an Array in One Cell Under Flatten

Flatten gives every array item its own column: `tags[0]`, `tags[1]`, `tags[2]`. A row with more items adds more columns. Choose **JSON cell** when you want the whole array in one cell.

### Mistake 3: Expecting Typed Numbers in the CSV

A CSV cell is text. Every value is written as text and nothing is coerced. The spreadsheet applies its own typing on import, so check an id column before you trust it.

### Mistake 4: Copying a Huge Output

Copy puts the whole CSV on the clipboard, which is slow for a large result. Use Download when the output fills more than a screen or two.

### Mistake 5: Reading a Missing BOM as Broken Data

Excel on Windows can show `Ã©` for `é` in a plain UTF-8 file. The data is correct and the file is fine. Turn on Excel BOM and download again.

## Tools Used in This Guide

- **[NDJSON to CSV](/convert/ndjson-to-csv/)** — One CSV row per JSON Lines record.
- **[CSV to NDJSON](/convert/csv-to-ndjson/)** — The reverse: rows into one JSON object per line.
- **[JSON to CSV](/convert/json-to-csv/)** — For a JSON array of objects.
- **[CSV Viewer](/convert/csv-viewer/)** — Open and sort the CSV without a spreadsheet app.
- **[CSV to Excel](/convert/csv-to-excel/)** — Turn the CSV into an .xlsx workbook.

## FAQ

**Q: Is FindUtils NDJSON to CSV free to use?**
A: Yes. The tool is free and needs no account. It converts one file at a time in the browser.

**Q: What is the difference between NDJSON, JSONL and JSON Lines?**
A: They name the same format: one JSON document per line. The extensions `.ndjson` and `.jsonl` both load here.

**Q: Why is my file refused as a JSON array?**
A: The text starts with `[` and parses as one array. Use [JSON to CSV](/convert/json-to-csv/) for that shape.

**Q: What happens to a line with a syntax error?**
A: The tool skips it, counts it, and names it by line number. Every other line still converts.

**Q: Can I keep nested objects in one column?**
A: Yes. Choose **JSON cell**. The value is written as JSON text and quoted per RFC 4180.

**Q: Is my data uploaded?**
A: No. The text is parsed in the browser and no request carries it. The same converter is on the FindUtils API as `ndjson_to_csv` for scripted use.

## Next Steps

Convert one file and check the first and last rows against the source before you build a report on them.

- Convert a file with [NDJSON to CSV](/convert/ndjson-to-csv/).
- Turn rows back into JSON Lines with [CSV to NDJSON](/convert/csv-to-ndjson/), and read the [CSV to NDJSON guide](/guides/csv-to-ndjson/) for that direction.
- Load JSON Lines straight into a database with [JSON to SQL](/convert/json-to-sql/), or read the [CSV to JSON guide](/guides/csv-to-json-guide/) for the row-to-object direction.

## Sources

- [JSON Lines](https://jsonlines.org/) — the format definition: one valid JSON value per line, UTF-8 text, LF line ends.
- [ndjson-spec](https://github.com/ndjson/ndjson-spec) — the newline-delimited JSON specification.
- [RFC 4180](https://www.rfc-editor.org/info/rfc4180/) — the CSV quoting and escaping rules this tool follows.
- [MDN: JSON.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) — how one JSON text is parsed, and why a whole JSON Lines file is not one text.
- [jq manual](https://jqlang.org/manual/) — `jq -c` writes compact output, one JSON value per line.
- [Import or export text (.txt or .csv) files](https://support.microsoft.com/en-us/excel/get-started/import-or-export-text-txt-or-csv-files) — Microsoft's guidance for opening a CSV in Excel.
