JSON Lines (JSONL) ⇔ JSON Array Converter

Convert between JSON Lines format — one JSON object per line — and a standard JSON array. Handy for checking machine learning datasets and log output.

Usage Tips

  • JSON Lines (JSONL) lists one independent JSON object per line, and is the standard format for OpenAI fine-tuning datasets and log output from tools like Elasticsearch/Logstash.
  • In "JSONL → JSON Array" mode, each line must be a separately parseable JSON object. Blank lines are skipped automatically.
  • In "JSON Array → JSONL" mode, the entire input must be a single JSON array (`[ ... ]`). Each element in the array is output as one line of JSONL.
  • Converting a large log file from JSONL to a JSON array makes it easier to work with using the `jq` command or a standard JSON array parser in your programming language of choice.

Frequently Asked Questions

A JSON array wraps everything in a single array like `[ {...}, {...} ]`, so you can't access individual elements without parsing the whole thing. JSON Lines, on the other hand, lists one independent JSON object per line, which can be streamed and processed line by line — making it well suited to sequential processing of huge log files or machine learning datasets.

It's the standard format for fine-tuning datasets on OpenAI and other machine learning platforms, the output format for log-collection tools like Elasticsearch and Logstash, and streaming large volumes of data — anywhere records need to be read and written independently, one at a time.

In "JSONL → JSON Array" mode, every line must be valid JSON on its own; if even one line has a syntax error, an error message showing that line number is displayed. In "JSON Array → JSONL" mode, the entire input must be an array (starting with `[` and ending with `]`).

A result converted to a JSON array can be used directly with the `jq` command or any standard JSON parser in your programming language. Conversely, a result converted to JSONL works well with `jq -c`, `grep`, `awk`, and other line-oriented tools, making it easy to plug into a log analysis pipeline.
ツールくん

Side Note — Why Was the "One Record per Line" Format Invented?

The JSON Lines format (also called JSONL) emerged because a standard JSON array has a fundamental limitation: you can't retrieve even a single record until the entire array has been loaded into memory and parsed. Trying to handle log data or machine learning training sets spanning millions of lines as a single JSON array meant loading the whole file into memory, which caused memory shortages and ballooning parse times for very large files.

JSON Lines solves this with a simple rule: one line equals one complete JSON object. Because a file can be read and parsed line by line as it goes, there's no need to load the entire file into memory, making it a natural fit for streaming and parallel processing. This design philosophy also lines up well with the traditional Unix "one record per line" text-processing culture — commands like `grep`, `awk`, and `sed` all operate line by line — which is a major practical advantage, since JSON Lines slots directly into existing command-line toolchains.

Today it's widely adopted as a distribution format for datasets in AI and machine learning, and it's now common for large language model training data and fine-tuning prompt/response pairs to be distributed in JSON Lines format.