-
Notifications
You must be signed in to change notification settings - Fork 0
JSONL Support
jvim provides first-class support for JSON Lines (.jsonl) files with automatic detection, pretty-printed editing, and compact saving.
JSONL mode is activated in two ways:
-
File extension: Files with
.jsonlextension are always treated as JSONL -
Content-based detection: For other extensions, jvim analyzes the content:
- The file must have 2 or more non-empty lines
- The entire content must not be valid as a single JSON value (to avoid treating a formatted JSON array as JSONL)
- Each non-empty line must be individually valid JSON
- If all conditions are met, JSONL mode activates automatically
This means you can use .json files containing JSONL data and jvim will detect them correctly.
When a JSONL file is opened, each record is automatically formatted with indent=4 for comfortable reading and editing:
On disk:
{"name": "Alice", "age": 30, "email": "alice@example.com"}
{"name": "Bob", "age": 25, "email": "bob@example.com"}
In jvim:
{
"name": "Alice",
"age": 30,
"email": "alice@example.com"
}
{
"name": "Bob",
"age": 25,
"email": "bob@example.com"
}When you save (:w), each record is automatically minified back to a single line, preserving the JSONL format. The conversion process:
- Splits the pretty-printed content into blocks (groups of consecutive non-empty lines)
- Parses each block as JSON
- Re-serializes each block as a compact single line
- Joins with newlines
This round-trip is lossless — your data is preserved exactly.
A second column in the gutter shows the JSONL record number (1, 2, 3...) next to the first line of each record. This makes it easy to identify which record you're viewing, especially when records span many lines.
The record index is cached and recalculated when the content changes.
When scrolling through a multi-line record, the physical line number of the record's first line stays visible at the top of the gutter. This provides context about which record you're currently viewing, even when the record header has scrolled off-screen.
JSONL mode provides special commands for navigating between records:
| Command | Description |
|---|---|
:N |
Jump to record N (1-indexed). In JSONL mode, numbers are interpreted as record numbers, not line numbers |
:pN |
Jump to record N explicitly (p = "position by record"). Same as :N in JSONL mode |
:lN |
Jump to line N (l = "line"). Bypasses JSONL record interpretation and goes to the actual editor line |
:1 → Jump to record 1 (first record)
:5 → Jump to record 5
:p10 → Jump to record 10
:l25 → Jump to editor line 25 (regardless of record boundaries)
:$ → Jump to last line
When using JSONPath search in JSONL mode, each record is parsed and searched independently. Results are mapped back to their positions in the pretty-printed editor view. See JSONPath Search for details.
JSONPath substitutions in JSONL mode operate on each record independently. The content is split into blocks, each block is parsed as a separate JSON document, and substitutions are applied per-record. See Substitute for details.
The diff viewer supports JSONL comparison with --jsonl flag (auto-detected for .jsonl files). Records are matched as units, and changed records are diffed line-by-line internally. See Diff Viewer for details.
When opening a file with :e, JSONL detection runs on the new file's content, automatically switching JSONL mode on or off as appropriate.