Skip to content

Function: parseJsonlFile()

Makaio Framework


Makaio Framework / ai-adapters-core/node / parseJsonlFile

parseJsonlFile<T>(options): Promise<JsonlParseResult<T>>

Defined in: ../../../adapters/core/src/log-importer/jsonl-parser.ts:145

Parse a JSONL file starting from a byte offset.

T

The expected type of each parsed JSON record

JsonlParserOptions

Parser configuration including file path and start offset

Promise<JsonlParseResult<T>>

Parse result with records, new byte offset, and any errors

Error if the file cannot be opened or read

JSONL files may be actively written to, leaving incomplete lines at the end. This parser only processes complete lines (lines ending with \n). Incomplete trailing content is left for the next read cycle.

Malformed JSON lines don’t stop parsing. The parser logs the error and continues to the next line. Callers should check the errors array and log/alert as appropriate.

The generic type T is not validated at runtime. Callers should either:

  1. Use Zod or similar to validate each record
  2. Use type guards before accessing properties
  3. Trust the source format (e.g., known tool log format)
interface LogRecord {
type: string;
timestamp: string;
data: unknown;
}
// First read (from beginning)
const result = await parseJsonlFile<LogRecord>({
filePath: '/path/to/logs.jsonl',
});
// Process records
for (const record of result.records) {
console.log(record.type);
}
// Store cursor for next read
await saveCursor(result.bytesRead);
// Later: resume from cursor
const cursor = await loadCursor();
const nextResult = await parseJsonlFile<LogRecord>({
filePath: '/path/to/logs.jsonl',
startOffset: cursor,
});