PaddlePaddle/PaddleOCR · error · ResultParseError
Failed to parse JSONL result payload.
Error message
Failed to parse JSONL result payload.
What it means
ResultParseError is thrown by fetchJsonl() when the result payload downloaded from the job's result URL cannot be parsed as JSON Lines: the body is split on newlines and every non-empty line must JSON.parse successfully. If any single line is malformed, the whole fetch fails with the original parse error attached as `cause`. This indicates the server-side result artifact is not valid JSONL, not that your code is wrong.
Source
Thrown at api_sdk/typescript/src/internal/http.ts:146
`${this.jobsUrl}/batch/${encodeURIComponent(batchId)}`,
{ method: "GET" },
signal,
true,
timeoutMs,
);
}
async fetchJsonl(url: string, signal?: AbortSignal, timeoutMs?: number): Promise<unknown[]> {
const resp = await this.fetch(url, { method: "GET" }, signal, false, timeoutMs);
const text = await resp.text();
try {
return text
.trim()
.split("\n")
.filter((line) => line.trim())
.map((line) => JSON.parse(line) as unknown);
} catch (error) {
throw new ResultParseError("Failed to parse JSONL result payload.", { cause: error });
}
}
async fetchResource(url: string, signal?: AbortSignal, timeoutMs?: number): Promise<ArrayBuffer> {
const resp = await this.fetch(url, { method: "GET" }, signal, false, timeoutMs);
return resp.arrayBuffer();
}
private async fetchJson<T>(
url: string,
init: RequestInit,
signal?: AbortSignal,
withAuth: boolean = true,
timeoutMs?: number,
): Promise<T> {
const resp = await this.fetch(url, init, signal, withAuth, timeoutMs);
let payload: APIResponse<T>;
try {View on GitHub (pinned to 2661c7c0ef)
Solutions
- Inspect the raw payload: fetch the result URL manually with curl and check each line with a JSONL validator to find the offending line number
- Retry the operation — a truncated or partially-written server artifact is often transient; a fresh job usually produces a valid file
- Check error.cause for the underlying SyntaxError, which includes the exact character position of the malformed JSON
- If the result URL is served through a proxy, bypass it or verify it is not mangling the body (gzip, ETag, HTML error pages)
Example fix
try {
const result = await client.extractFile("PP-StructureV3", filePath, {});
} catch (e) {
if (e instanceof ResultParseError) {
console.error("JSONL line failed:", e.cause); // SyntaxError with position
}
throw e;
} Defensive patterns
Strategy: retry
Validate before calling
function isLikelyJsonl(text: string): boolean {
const lines = text.trim().split("\n").filter((l) => l.trim());
return lines.length > 0 && lines.every((l) => {
try { JSON.parse(l); return true; } catch { return false; }
});
} Type guard
function isJsonlPayload(v: unknown): v is unknown[] {
return Array.isArray(v);
} Try / catch
try {
const result = await poller.waitForResult(jobId);
} catch (e) {
if (e instanceof ResultParseError) {
if (e.cause instanceof SyntaxError) {
// artifact corruption — retry the job once, then report
return retryJob(jobId);
}
}
throw e;
} Prevention
- Treat ResultParseError as transient first: re-submit and re-download before debugging
- Log e.cause (SyntaxError position) to identify which JSONL line is malformed
- Verify no proxy sits between you and the result storage host if errors persist
When it happens
Trigger: Awaiting job completion (e.g. via the poller) which then calls fetchJsonl(resultJsonUrl) on a done job, and the downloaded result contains a truncated or corrupted line — e.g. a line break inside a JSON string value, a partially written result file, an HTML error page from a CDN, or a truncated body caused by a network interruption mid-download.
Common situations: Result files whose text fields contain embedded raw newlines (multi-page OCR text); a proxy/CDN serving a cached 200 HTML page instead of the JSONL; very large results truncated in transit; API version drift changing the artifact format.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Malformed JSONL result payload: {e}
- File not found: ${path}
- Expected a JSON response body.
- PaddleOCR official API request failed.
- Response body is missing data.
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/3bbf24969d58589a.
Report an issue: GitHub.