Working with JSONL tables in TypeScript
Updated Nov 12, 2026
JSONL (JSON Lines) file handling with automatic format detection.
Installation
npm install fairspecGetting Started
The JSONL format is handled by the JSON plugin, which provides:
loadJsonTable- Load JSONL files into tablessaveJsonTable- Save tables to JSONL filesJsonPlugin- Plugin for framework integration
For example:
import { loadJsonTable } from "fairspec"
const table = await loadJsonTable({ data: "table.jsonl" })
// Newline-delimited JSON objectsLoaders return a nodejs-polars LazyDataFrame: call .collect() to get a DataFrame. Savers take any LazyDataFrame, so pass df.lazy() to save a DataFrame.
Basic Usage
Loading JSONL Files
import { loadJsonTable } from "fairspec"
// Load from local file
const local = await loadJsonTable({ data: "data.jsonl" })
// Load with explicit format
const custom = await loadJsonTable({
data: "data.jsonl",
fileDialect: { format: "jsonl" },
})
// Load multiple files (concatenated)
const combined = await loadJsonTable({
data: ["part1.jsonl", "part2.jsonl"],
})Saving JSONL Files
import { saveJsonTable } from "fairspec"
// Save as JSONL
await saveJsonTable(table, {
path: "output.jsonl",
fileDialect: { format: "jsonl" },
})Standard Format
JSONL uses newline-delimited JSON objects:
{"id": 1, "name": "Alice", "age": 30}
{"id": 2, "name": "Bob", "age": 25}
{"id": 3, "name": "Charlie", "age": 35}A blank line, or one holding only spaces, tabs and a carriage return, is not a row and takes no row number.
Advanced Features
Column Selection
Select specific columns using columnNames:
import { loadJsonTable } from "fairspec"
// Only load specific columns
const table = await loadJsonTable({
data: "data.jsonl",
fileDialect: {
format: "jsonl",
columnNames: ["name", "age"],
},
})Array Format Handling
Handle CSV-style array data with rowType: "array":
import { loadJsonTable } from "fairspec"
// Input JSONL with arrays:
// ["id", "name"]
// [1, "Alice"]
// [2, "Bob"]
const table = await loadJsonTable({
data: "data.jsonl",
fileDialect: {
format: "jsonl",
rowType: "array",
},
})Remote File Loading
import { loadJsonTable } from "fairspec"
// Load from URL
const remote = await loadJsonTable({
data: "https://example.com/data.jsonl",
})
// Load multiple remote files
const remoteParts = await loadJsonTable({
data: [
"https://api.example.com/logs-2023.jsonl",
"https://api.example.com/logs-2024.jsonl",
],
})Created with โค and Livemark