apple/pkl · error · ParseException
',' or '}'
Error message
',' or '}'
What it means
After each object member value, the parser expects either a comma (to continue with more members) or a closing brace. If neither is found, readObject throws expected("," or "}"). This catches malformed JSON such as missing commas between members, trailing commas followed by garbage, or an unclosed object at end of input.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/util/json/JsonParser.java:197
return;
}
do {
skipWhiteSpace();
handler.startObjectName(object);
var name = readName();
handler.endObjectName(object, name);
skipWhiteSpace();
if (!readChar(':')) {
throw expected("':'");
}
skipWhiteSpace();
handler.startObjectValue(object, name);
readValue();
handler.endObjectValue(object, name);
skipWhiteSpace();
} while (readChar(','));
if (!readChar('}')) {
throw expected("',' or '}'");
}
nestingLevel--;
handler.endObject(object);
}
private String readName() throws IOException {
if (current != '"') {
throw expected("name");
}
return readStringInternal();
}
private void readNull() throws IOException {
handler.startNull();
read();
readRequiredChar('u');
readRequiredChar('l');
readRequiredChar('l');View on GitHub (pinned to f3efcbfc9b)
Solutions
- Run the input through a JSON validator/formatter; the ParseException position points at the character where ',' or '}' was missing.
- Remove trailing commas before the closing '}' — strict JSON forbids them.
- Insert the missing ',' between consecutive object members or add the closing '}'.
- If input is truncated, check the producer/upstream for the complete document before parsing.
Example fix
// before
String json = "{\"a\": 1, \"b\": 2,}"; // trailing comma
// after
String json = "{\"a\": 1, \"b\": 2}"; Defensive patterns
Strategy: validation
Validate before calling
// Strip trailing commas and validate before parsing
String cleaned = json.replaceAll(",\\s*([}\\]])", "$1");
// then validate with any strict JSON parser before parse() Try / catch
try {
parser.parse(json);
} catch (ParseException e) {
throw new IllegalArgumentException("Malformed object syntax at " + e.getLocation().line + ":" + e.getLocation().column + " — expected ',' or '}'", e);
} Prevention
- Remove trailing commas — they are invalid in strict JSON.
- Use a JSON formatter on hand-edited files before committing.
- Generate documents with a serializer instead of concatenating fragments.
- Check for truncated input (verify end of document) before parsing.
When it happens
Trigger: parse() on input like "{\"a\":1 \"b\":2}" (missing comma), "{\"a\":1,}" followed by something other than '}', or "{\"a\":1" (EOF where '}' was expected).
Common situations: Hand-edited JSON files with missing commas, trailing commas copied from JavaScript (legal in JS objects, illegal in strict JSON), string concatenation of fragments that omits separators, truncated responses stored to disk.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/9bbb16094ac2f4cd.
Report an issue: GitHub.