Consume JSONL and CSV safely
Read committed shards incrementally, preserve provenance, and hand clean records to analysis tools.
In this guide
1. Identify the files
DatasetJob writes numbered data shards, corresponding error shards, report.json, manifest.jsonl and a state directory. JSONL contains one JSON object per line. CSV shards each contain a header.
Keep the entire output directory while a job may need to resume. The checkpoint database and committed shards belong together. Use one active writer per output directory.
datasets/pages/
report.json
manifest.jsonl
part-00000000.jsonl
part-00000000.errors.jsonl
state/2. Respect the committed boundary
After a completed or cancelled invocation has returned, report.shards describes the committed shard count. After a hard crash, resume first: report.json can be stale and files from an unfinished batch can remain.
Do not discover every matching file and assume it is committed. Read the numbered shards up to the report boundary, and treat a missing expected file as an error rather than silently skipping it.
3. Stream records with Python
This example reads a returned, completed report and then streams one committed JSONL shard at a time. Replace the output path with your own. It intentionally stops when the run contains errors; adapt this acceptance policy only after deciding how partial data will be handled.
import json
from pathlib import Path
root = Path("datasets/pages")
with (root / "report.json").open(encoding="utf-8") as file:
report = json.load(file)
if (not report["complete"] or report["cancelled"]
or report["pages_failed"] or report["records_rejected"]):
raise SystemExit("Review the job before consuming its output")
count = 0
for index in range(report["shards"]):
shard = root / f"part-{index:08d}.jsonl"
with shard.open(encoding="utf-8") as source:
for line in source:
record = json.loads(line)
# Replace this with a bounded downstream operation.
print(record["_source_url"], record.get("title", ""))
count += 1
if count != report["records_written"]:
raise RuntimeError("Committed row count does not match the report")
print(f"Read {count} committed records")4. Stream records with Node.js
The Node example uses readline rather than loading the entire dataset into an array. It reads the same committed shard range and checks the observed record count.
import { createReadStream } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { createInterface } from 'node:readline';
const root = 'datasets/pages';
const report = JSON.parse(await readFile(join(root, 'report.json'), 'utf8'));
if (!report.complete || report.cancelled || report.pages_failed || report.records_rejected) {
throw new Error('Review the job before consuming its output');
}
let count = 0;
for (let index = 0; index < report.shards; index++) {
const name = 'part-' + String(index).padStart(8, '0') + '.jsonl';
const lines = createInterface({ input: createReadStream(join(root, name)), crlfDelay: Infinity });
for await (const line of lines) {
const record = JSON.parse(line);
console.log(record._source_url, record.title ?? '');
count++;
}
}
if (count !== report.records_written) throw new Error('Committed row count mismatch');
console.log('Read', count, 'committed records');5. Read CSV as CSV
Each CSV data shard contains its own header. Parse every shard independently or use a CSV library that understands repeated headers. Concatenating files blindly can insert header rows into your data.
CSV quoting handles commas, quotes and newlines within fields. Do not split rows on commas or lines manually. The same report and shard-boundary checks apply.
6. Convert values deliberately
Job field values are exported as strings, including values checked with integer, float or boolean data types. _source_url and _row are also strings. Convert fields in the downstream step according to your own schema.
An empty value, a default and a failed conversion are distinct cases. Record how you handle each, especially if the derived dataset will be used for analysis.
raw_number = record["pep_number"]
number = int(raw_number)
if number < 0:
raise ValueError("Expected a nonnegative proposal number")7. Use analysis tools with bounded expectations
pandas and DuckDB can read exported files, but loading all rows into a DataFrame is a separate memory decision. For large data, use chunks or a database query engine and measure memory on your actual workload.
Crawlingo does not automatically create a pandas DataFrame, publish a database table or create embeddings. Those are explicit downstream steps owned by your application.
8. Keep the source trail
_source_url identifies the page fetched by the job. _row is the extracted row position. Preserve the source URL, source-specific identifier and snapshot date in derived data, and keep a link to the raw output and configuration.
Do not use _row as a durable identifier across repeated snapshots: rows can move when the source changes. Use a stable source identifier when available.
9. Publish or upload as a separate step
Decide whether to publish only data shards or also reports, errors and metadata. Keep any sensitive source material and credentials out of public artifacts. Make downstream storage and access controls the responsibility of your own application.
If you need to resume later, retain the original state and shards in durable storage together. Uploading a copy of data files alone does not create a resumable remote checkpoint.