JSON Lines to JSON

Wrap newline-delimited records into a JSON array.

Reverse
Input
JSONL input
Output
Result
Options

Spaces per level of nesting.

About this tool


This collects every line of a JSON Lines file into a single JSON array, which is what most parsers, APIs and JavaScript code expect. It is the fix for the common error "Unexpected non-whitespace character after JSON". That message almost always means you handed a JSON Lines file to a JSON parser.

Because each line is parsed independently, a malformed record can be pinpointed exactly: you get its line number instead of a single failure for the entire file.

How to use it

  1. Paste or upload JSON LinesDrop a .jsonl file onto the input pane, use the file picker, or paste the text directly.
  2. Adjust the options if neededThe defaults suit most input. Open Options to change how values are interpreted or formatted.
  3. ConvertPress Convert to JSON, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Read any warningsWarnings explain anything that could not be represented exactly in the target format.
  5. Copy or downloadCopy the result, or download it as a .json file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

JSON Lines to JSON

Input

{"id":1,"name":"Alice"}
{"id":2,"name":"Bob"}

Output

[
  {
    "id": 1,
    "name": "Alice"
  },
  {
    "id": 2,
    "name": "Bob"
  }
]

The lines are wrapped into one array and formatted for reading.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

Each line is parsed on its own
Every non-empty line must be one complete JSON value. Records cannot span multiple lines, so a pretty-printed object broken across lines is invalid here. That is the constraint that makes streaming possible in the first place.
Errors name the failing line
When a line does not parse, the error reports its line number and the specific problem. That is a real advantage over standard JSON parsing, where one bad character anywhere invalidates the whole document with a single offset.
Blank lines are skipped
Empty and whitespace-only lines are ignored rather than treated as errors, since a trailing newline at the end of a file is normal and log writers often emit stray blank lines.
Mixed record shapes are allowed
JSON Lines does not require records to share a schema, so lines may hold objects, arrays or scalars in any combination. They are all collected into the array as they are. Most consumers expect uniform objects, so a warning appears if the records are not all objects.

Limitations


  • Each record must occupy exactly one line.
  • Loading a very large NDJSON file builds the whole array in memory at once.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


My JSON file gives "Unexpected non-whitespace character after JSON". Is this the fix?
Almost certainly. That error means the file holds several JSON values one after another, which is JSON Lines rather than JSON. This tool wraps them into a proper array.
Why does my multi-line record fail?
JSON Lines requires each record to occupy exactly one line. A pretty-printed object spanning several lines breaks that rule, minify each record first.
Does the whole file have to have a consistent schema?
No. Records can differ, and all are collected. A warning appears when they are not all objects, since most downstream tools assume uniform records.