Working with JSONL tables in TypeScript
JSONL (JSON Lines) file handling with automatic format detection and high-performance data operations.
Installation
Section titled “Installation”npm install fairspecGetting Started
Section titled “Getting 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 objectsBasic Usage
Section titled “Basic Usage”Loading JSONL Files
Section titled “Loading JSONL Files”import { loadJsonTable } from "fairspec"
// Load from local fileconst table = await loadJsonTable({ data: "data.jsonl" })
// Load with explicit formatconst table = await loadJsonTable({ data: "data.jsonl", format: { name: "jsonl" }})
// Load multiple files (concatenated)const table = await loadJsonTable({ data: ["part1.jsonl", "part2.jsonl"]})Saving JSONL Files
Section titled “Saving JSONL Files”import { saveJsonTable } from "fairspec"
// Save as JSONLawait saveJsonTable(table, { path: "output.jsonl", format: { name: "jsonl" }})Standard Format
Section titled “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}Advanced Features
Section titled “Advanced Features”Column Selection
Section titled “Column Selection”Select specific columns using columnNames:
// Only load specific columnsconst table = await loadJsonTable({ data: "data.jsonl", format: { name: "jsonl", columnNames: ["name", "age"] }})Array Format Handling
Section titled “Array Format Handling”Handle CSV-style array data with rowType: "array":
// Input JSONL with arrays:// ["id", "name"]// [1, "Alice"]// [2, "Bob"]
const table = await loadJsonTable({ data: "data.jsonl", format: { name: "jsonl", rowType: "array" }})Remote File Loading
Section titled “Remote File Loading”// Load from URLconst table = await loadJsonTable({ data: "https://example.com/data.jsonl"})
// Load multiple remote filesconst table = await loadJsonTable({ data: [ "https://api.example.com/logs-2023.jsonl", "https://api.example.com/logs-2024.jsonl" ]})