How to fix common JSONL errors
Updated November 4, 2026
Most JSONL errors come from a few mistakes: a file that is really formatted JSON, a trailing comma, Python output instead of JSON, or a stray blank line. To find them all at once, run your file through the JSONL validator, which reports each bad line with the fix.
The file is a JSON array
Symptom: line 1 is [, and parsers fail on the first line.
JSONL has no surrounding brackets. Convert the file with the JSON to JSONL converter, or use jq:
jq -c '.[]' data.json > data.jsonl
The file is pretty-printed
Symptom: a line contains only {, or a fragment such as "name": "Ada",.
Each record has to sit on a single line. In Python, the cause is usually indent:
# Wrong: spreads each record over several lines
f.write(json.dumps(record, indent=2) + "\n")
# Right
f.write(json.dumps(record) + "\n")
To repair an existing file, use the JSON to JSONL converter, which also accepts pretty-printed objects, or jq -c . data.json.
A line ends with a comma
Symptom: a record is valid apart from a , at the end.
Records are separated by newlines alone. This often happens when a JSON array is edited into JSONL by hand. Remove the comma from each line.
Single quotes, None, True or False
Symptom: a line looks like {'a': None, 'b': True}.
That is a printed Python dict rather than JSON. Writing str(record) or print(record) causes it. Use json.dumps(record) instead, which produces double quotes, null and true.
NaN or Infinity
Symptom: a line contains NaN or Infinity.
Standard JSON has no such values, although Python’s json.dumps writes them by default. Pass allow_nan=False to catch them, and convert them to null first.
Blank lines
Symptom: the error points to an empty line, often the last one.
The JSON Lines format treats blank lines as invalid, and some parsers reject them. To remove them:
sed -i '/^\s*$/d' data.jsonl
A single newline at the end of the file is fine, and does not count as a blank line.
Byte order mark
Symptom: line 1 fails even though it looks fine, sometimes with an error about an unexpected character.
Some Windows tools add a byte order mark, which the format does not allow. Save the file as “UTF-8” rather than “UTF-8 with BOM”. The merge tool also drops byte order marks when it combines files.
Duplicate custom_id
Symptom: a batch API rejects the file for repeated IDs.
Each custom_id must be unique within a batch file, because it is how you match results to requests. Choose the OpenAI or Anthropic profile in the validator to list duplicates.
File too large for a batch
Symptom: the provider rejects the file for size or request count.
OpenAI allows 50,000 requests and 200 MB per file. Anthropic allows 100,000 requests or 256 MB per batch. Use the JSONL splitter, which has a preset for each.