VS Code JSONL Formatter: What Formatting Changes and When to Avoid It
A practical review of formatting JSONL files in Visual Studio Code: what changes, why pretty-printing can break JSON Lines, and how to inspect records safely.
If you are looking for a JSONL formatter in VS Code, first decide what "format" should mean. In ordinary JSON, formatting usually means pretty-printing: adding line breaks and indentation so nested objects are easy to read. In JSON Lines (JSONL), line breaks carry meaning. Each line is one complete record. A formatter that treats a JSONL file like ordinary JSON can turn a valid file into one that no longer parses as JSONL. This review explains what different kinds of formatting change, when each is safe, and when to leave the file as plain one-record-per-line text.
Short answer: is formatting JSONL in VS Code suitable for your use?
Formatting is suitable when it only changes whitespace inside each line, or when it gives you a read-only, expanded view while the file on disk stays one record per line. The main benefit is readability: long, dense records become easier to scan and debug. The decisive tradeoff is that any change that spreads one record across several lines breaks the JSON Lines structure. Tools that read the file line by line, such as data loaders, log processors and streaming pipelines, will then fail or misread it.
Keep the plain, compact form when the file feeds another program, when you are about to commit or share it as data, or when you cannot confirm what your formatter will do to line breaks. Expanded formatting is best treated as a temporary view, not as a saved change.
What JSONL is and how it differs from JSON
A JSON file normally holds a single JSON value, often an array or object, and whitespace between tokens has no meaning. A JSON Lines file holds many independent JSON values, one per line, separated by newline characters. Under the common JSON Lines convention, each line must be a valid JSON value on its own, and the newline is the record separator. Because of this, a JSONL file as a whole is usually not valid JSON. Likewise, a pretty-printed JSON array is not valid JSONL.
{"id": 1, "name": "alpha", "tags": ["a", "b"]}
{"id": 2, "name": "beta", "tags": []}
{"id": 3, "name": "gamma", "tags": ["c"]}
The example above is three records on three lines. A JSON parser given the whole file would typically report an error after the first record. A JSONL reader handles it as three separate values.
What a formatter actually changes
Formatting changes stored characters. Unlike visual effects such as syntax coloring or editor word wrap, a formatter rewrites the whitespace in the file when you save. For JSONL, the useful question is which whitespace it touches. There are three distinct operations:
- Within-line normalization: adjusts spacing inside a record, for example after colons and commas, but keeps each record on one line. The data and the line structure are preserved.
- Compaction: removes optional whitespace so each record is as short as possible on a single line. This is the safe direction for JSONL, and it is often what pipelines expect.
- Pretty-printing or expansion: inserts line breaks and indentation inside records. This is readable, but the saved result is no longer valid JSONL.
Here is what expansion does to the first record from the earlier example. The values are unchanged, but one record now spans several lines, so a line-based reader would see fragments rather than records:
{
"id": 1,
"name": "alpha",
"tags": [
"a",
"b"
]
}
Editor features that do not change stored characters are a separate category. Word wrap, folding, syntax highlighting and hover information only affect how the file looks in the editor. They are safe for JSONL because the bytes on disk stay the same. If your goal is simply to read a long record comfortably, these display-only features avoid the risk entirely.
How VS Code treats .jsonl files
VS Code decides which formatter and validator to use from the language mode assigned to a file. That mode is shown in the status bar and can be changed there or through the files.associations setting. The behavior you get depends on that mode:
- If a .jsonl file is opened as plain text, there is no JSON validation and Format Document has nothing JSON-aware to run. The file is safe from accidental expansion, but you get no error checking.
- If you switch the file to the regular JSON mode to get highlighting or formatting, the JSON validator will usually flag everything after the first record as an error, because it expects a single value. Running Format Document in that mode may fail or produce output that is not valid JSONL. Check the result before saving.
- If an extension provides a dedicated JSON Lines mode, its behavior is whatever that extension documents. Read its description and test on a copy before trusting it with real data.
Evidence gap: no documentation or test results were available for this review on whether a specific VS Code version ships a built-in JSON Lines language mode, or on how any named extension formats or validates JSONL. Treat the points above as general behavior that follows from how language modes work, not as verified claims about a particular release or extension. Before relying on any formatter, run it on a copy and confirm that the output has the same number of lines as there are records.
A safe workflow: compact on disk, expand only to inspect
A reliable pattern is to keep the saved file compact and do any expansion in a separate, throwaway view. One widely used command-line option is jq, which you can run from VS Code's integrated terminal. With the -c flag, it reads each value in a JSONL file and writes each back as a single compact line. Without -c, it pretty-prints each record, which is useful for reading but should not overwrite the original.
# Normalize/compact: one record per line, suitable to save as JSONL
jq -c . input.jsonl > output.jsonl
# Inspect: expanded view for reading only (output is not JSONL)
jq . input.jsonl | less
Parsing every record this way also acts as a basic validation pass. If a line is not valid JSON, jq stops with an error, which tells you the file needs attention before it goes further. Keep in mind that this checks syntax only. It does not check that records follow any schema your application expects.
Will the result stay usable after copying or sharing?
For JSONL, usability after copying depends almost entirely on line breaks surviving intact. Points to check:
- Copy and paste: copying compact records between editors and terminals generally preserves them because each record is plain text on one line. Pasting into destinations that wrap or reflow text, such as some chat or document tools, may insert or remove line breaks. Recheck the line count after pasting into anything other than a code editor or terminal.
- Line endings: some environments convert newlines to carriage-return-plus-newline. JSON parsers generally treat the extra carriage return as whitespace, but strict tools may differ. If a downstream tool complains, check line endings first.
- Trailing newline and blank lines: a final newline after the last record is conventional. Stray blank lines may be rejected or skipped depending on the reader.
- Editing: expanded records are easier to edit by hand, but you must compact them again before saving. A half-reformatted file, where some records are expanded and others are not, is a common source of hard-to-spot failures.
- Search: line-based tools such as grep match whole records when the file is compact, which is convenient. After expansion, a match returns only a fragment of a record.
- Accessibility: formatting JSONL changes only whitespace, not characters, so it does not introduce substituted glyphs or reordered text that would confuse assistive technology. Very long single-line records can still be tedious to navigate with a screen reader. Reading an expanded view, while keeping the compact file as the stored version, is a reasonable approach. No screen-reader testing of VS Code with JSONL files was available for this review, so specific assistive-technology behavior is not verified here.
Choosing an approach
| Goal | Recommended approach | Saved file stays valid JSONL? |
| Read a long record comfortably | Word wrap or a separate expanded view | Yes |
| Check every line parses | Line-by-line validation, for example with jq | Yes |
| Clean up inconsistent spacing | Compact or within-line normalization | Yes |
| Edit a nested record by hand | Expand a copy, edit, then compact before saving | Only after compacting |
| Share data with another program | Keep plain compact JSONL | Yes |
| Pretty-print the whole file and save | Avoid for JSONL | No |
Bottom line
A VS Code JSONL formatter is worth using if it keeps each record on its own line, either by compacting or by normalizing spacing within lines, or if it shows an expanded view without saving it. Anything that pretty-prints records across lines and writes the result back trades data integrity for readability, and that is rarely the right trade for a file other tools will consume. When you are unsure how a particular formatter behaves, leave the file as plain compact text, validate it line by line, and do your reading in a separate expanded view.