Skip to content

JSONL Support

edgar edited this page Feb 23, 2026 · 1 revision

JSONL Support

jvim provides first-class support for JSON Lines (.jsonl) files with automatic detection, pretty-printed editing, and compact saving.

Automatic Detection

JSONL mode is activated in two ways:

  1. File extension: Files with .jsonl extension are always treated as JSONL
  2. 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.

Pretty-Print Editing

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"
}

Compact Saving

When you save (:w), each record is automatically minified back to a single line, preserving the JSONL format. The conversion process:

  1. Splits the pretty-printed content into blocks (groups of consecutive non-empty lines)
  2. Parses each block as JSON
  3. Re-serializes each block as a compact single line
  4. Joins with newlines

This round-trip is lossless — your data is preserved exactly.

Record Numbers

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.

Floating Header

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.

Record Navigation

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

Examples

: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

JSONL-Specific Behaviors

Search

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.

Substitute

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.

Diff

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.

File Open (:e)

When opening a file with :e, JSONL detection runs on the new file's content, automatically switching JSONL mode on or off as appropriate.


한국어 | Home

Clone this wiki locally