Tutorial · 5 min read
How to Convert JSON Lines (NDJSON) to CSV Online
JSON Lines (NDJSON) is the go-to format for streaming data, log files, and big data pipelines. Each line is a complete JSON object — perfect for processing line by line. Use a NDJSON to CSV converter to transform these streams into tabular data for analysis.
1. What is NDJSON
NDJSON (Newline Delimited JSON) is a simple format where each line is a valid JSON object. Unlike a JSON array, the entire file is not a single JSON structure — which makes it streamable:
This format is widely used in:
- Log files — Each log entry is a JSON line with timestamp, level, and message.
- Streaming APIs — Twitter, Kafka, and event streams produce NDJSON.
- Big data pipelines — Spark, Hadoop, and ETL tools use JSON Lines.
CSV is the natural target format because each JSON object becomes one CSV row.
2. Auto-Detection of NDJSON Format
A good converter automatically detects whether your input is NDJSON or regular JSON:
- Check structure. If the input starts with
{and each top-level line is a complete object, it's NDJSON. - Fallback to array. If the input is a JSON array
[{...},{...}], the converter unwraps it and treats each element as a row. - Mixed content. Some files mix NDJSON and array-format content. The converter normalizes both.
JSONXX's NDJSON converter detects the format automatically, so you don't need to think about it.
3. Handling Inconsistent Fields Across Lines
Real-world NDJSON often has inconsistent field names. Log files, for example, may have optional fields that only appear in some entries:
The converter handles this by:
- Full scan. It reads all lines first to collect every unique field name.
- Union schema. All fields from all lines become columns. Missing values become empty cells.
- Consistent ordering. Columns follow the order fields first appear, making the CSV predictable.
This is especially important when dealing with nested NDJSON — see the nested NDJSON handling guide for advanced cases.
4. Encoding for Excel Compatibility
When converting NDJSON to CSV for Excel, encoding matters:
- UTF-8 with BOM. Excel on Windows needs a BOM (Byte Order Mark) to correctly recognize UTF-8. Without it, special characters may appear garbled.
- Quoting. If your JSON values contain commas, newlines, or quotes, the CSV must properly quote them. The converter handles this automatically.
- Date formats. ISO 8601 date strings in JSON are preserved as-is in CSV. Excel may auto-format them — use the Text import wizard to keep them as strings.
JSONXX's converter adds the BOM and handles quoting automatically, producing Excel-ready CSVs.
5. Large File Processing Tips
Processing large NDJSON files requires some strategy:
- Upload vs paste. For files over 5MB, use the upload button instead of pasting. Uploads are handled more efficiently by the browser.
- Sample first. If you have a massive file, take the first 1,000 lines as a sample. Convert that to understand the schema, then process the full file.
- Browser limits. The tool handles files up to 50MB. For larger files, use
jq -ror python scripts on the command line. - Check the output. After conversion, open the CSV in a text editor first to verify columns look correct before opening in Excel.
For post-conversion analysis, use the JSON to Excel or JSON Editor tools for additional transformations.
Convert NDJSON to CSV Now
Auto-detects NDJSON, handles inconsistent fields, produces Excel-ready CSV output.
Convert NDJSON Now →Frequently Asked Questions
What's the difference between NDJSON and JSONL?
NDJSON and JSONL are the same format — one JSON object per line separated by newlines. NDJSON is the formal spec name; JSONL is the common file extension.
How does the converter handle inconsistent fields across lines?
It scans all lines to collect every unique field name. Lines with missing fields get empty values in the CSV. Lines with extra fields get additional columns.
Is there an upload size limit?
The converter handles files up to 50MB in the browser. For larger files, split into chunks or use a command-line tool like jq.
Can I convert compressed NDJSON files?
Not directly in browser-based tools. Decompress .gz or .zip files first using a standard decompression tool, then upload the plain NDJSON.
Are there CSV row limits I should worry about?
Excel supports up to 1,048,576 rows per sheet. If your NDJSON exceeds this, split the CSV into multiple files before opening in Excel.
Looking for more guides? See the full JSONXX How To index.