SmartQueryTools

Convert NDJSON to CSV Online

Convert NDJSON files to CSV format directly in your browser. No upload required — your data never leaves your device.

About converting NDJSON to CSV

NDJSON to CSV is the standard way to get log and event data into a spreadsheet or a warehouse staging table. Structured loggers such as Pino, Bunyan and structlog write one JSON object per line, and so do mongoexport, elasticdump, BigQuery JSON exports and most change-data-capture tools. Each line becomes a CSV row, and the keys found across all lines become the header.

The reader is strict. Every non-empty line must be a complete JSON object. Blank lines are skipped, but the first malformed line stops the whole load with an error naming its line number. The usual culprits are a log file cut off mid-write, a stack trace printed as plain text between JSON lines, or a pretty-printed object spread over several lines. The reader is also chosen by file extension, so a file ending in .log or .txt is parsed as CSV; rename it to .jsonl first.

Log records are rarely flat. Pino nests error details under err, and mongoexport writes IDs and dates in Extended JSON as {"$oid": "..."} and {"$date": "..."}. Those values are objects, and in the CSV they show up as JSON text such as {"$oid":"65f1..."}. Flatten NDJSON splits ordinary nested objects such as err into columns like err_message before you convert. For Extended JSON, select the inner values in the SQL Query tool, for example _id."$oid", and export that result as CSV.

Not sure which format you need? Read the NDJSON vs CSV comparison.

Worked example

A small sample file, converted with the default settings.

Input (NDJSON)

{"ts":"2026-03-02T14:05:11.042Z","level":"info","service":"checkout","status":200,"latency_ms":41.7,"user_id":"u_1842"}
{"ts":"2026-03-02T14:05:12.310Z","level":"error","service":"checkout","status":502,"latency_ms":3012.4,"user_id":null}
{"ts":"2026-03-02T14:05:12.877Z","level":"info","service":"search","status":200,"latency_ms":12.9,"user_id":"u_0077"}
{"ts":"2026-03-02T14:05:14.105Z","level":"warn","service":"search","status":429,"latency_ms":0.8,"user_id":"u_1842"}

Output (CSV)

ts,level,service,status,latency_ms,user_id
2026-03-02T14:05:11.042Z,info,checkout,200,41.7,u_1842
2026-03-02T14:05:12.310Z,error,checkout,502,3012.4,
2026-03-02T14:05:12.877Z,info,search,200,12.9,u_0077
2026-03-02T14:05:14.105Z,warn,search,429,0.8,u_1842

What changes when you convert NDJSON to CSV

  • Each line becomes one CSV row, in file order. The header is ts,level,service,status,latency_ms,user_id.
  • ts values such as 2026-03-02T14:05:11.042Z are copied as text. ISO timestamps that carry milliseconds, the JavaScript toISOString format, are not converted to a date type.
  • The error line has "user_id":null, so its last field is empty. A line that leaves a key out entirely also gets an empty field.
  • status and latency_ms stay numeric, so 502 and 3012.4 appear without quotes.
  • Nested objects such as err or an Extended JSON _id, and arrays such as tags, are written as compact JSON text in one field.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Frequently Asked Questions

The conversion fails with "Malformed JSON ... in line N". What now?

Open the file at that line. It is usually a truncated final line from a log that was still being written, a plain-text line such as a stack trace, or an object split across several lines. Delete or repair it and load the file again. Blank lines are fine and are skipped.

Why do my MongoDB _id values show as {"$oid":"..."}?

mongoexport writes ObjectIds as {"$oid": "..."}, which is a nested object, so the CSV keeps it as JSON text. In the SQL Query tool, run SELECT _id."$oid" AS id, * EXCLUDE (_id) FROM your table and export the result as CSV. Alternatively, run mongoexport with --type=csv and --fields to get CSV straight from MongoDB.

My log file ends in .log. Can I still convert it?

Rename it to .jsonl or .ndjson first. The file type is detected from the extension, and anything unrecognised is parsed as CSV, which splits each JSON line at its commas and produces a meaningless table.

What is CSV format?

CSV (Comma-Separated Values) is a plain-text tabular format supported by virtually every data tool, spreadsheet app, and programming language.

Related Tools