apple/pkl · error · ParseException
name
Error message
name
What it means
Object member names in JSON must be double-quoted strings. In readObject, before each member the parser calls readName, which checks that the current character is '"'; if not, it throws expected("name"). This rejects unquoted or wrongly-typed keys such as JavaScript-style identifiers.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/util/json/JsonParser.java:205
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');
handler.endNull();
}
private void readTrue() throws IOException {
handler.startBoolean();
read();
readRequiredChar('r');
readRequiredChar('u');View on GitHub (pinned to f3efcbfc9b)
Solutions
- Quote every object key with double quotes: {"name": 1} instead of {name: 1}.
- Run the text through a strict-JSON formatter/validator before parsing to catch all unquoted keys at once.
- If the data is a JS/Python literal, serialize it properly (JSON.stringify / json.dumps) rather than stringifying the value directly.
- Catch ParseException and use its line/column to locate the offending key.
Example fix
// before
String json = "{name: \"pkl\"}"; // unquoted key
// after
String json = "{\"name\": \"pkl\"}"; Defensive patterns
Strategy: validation
Validate before calling
// Java: detect unquoted object keys before parsing
static boolean hasUnquotedKeys(String json) {
return java.util.regex.Pattern.compile("[{,]\\s*[A-Za-z_$][\\w$]*\\s*:").matcher(json).find();
}
if (hasUnquotedKeys(json)) throw new IllegalArgumentException("JSON object keys must be double-quoted"); Try / catch
try {
parser.parse(json);
} catch (ParseException e) {
if (e.getMessage().contains("name")) {
throw new IllegalArgumentException("Unquoted or invalid object key at " + e.getLocation().line + ":" + e.getLocation().column, e);
}
throw e;
} Prevention
- Always double-quote object keys.
- Serialize JS objects/Python dicts with the proper JSON encoder, not toString.
- Lint JSON files in CI to catch unquoted keys early.
- Avoid pasting JavaScript literals into JSON config files.
When it happens
Trigger: parse() on objects whose keys are not quoted: "{name: 1}", "{1: 'x'}" (numeric key), or any other token where a quoted name was required after '{' or ','.
Common situations: Pasting JavaScript object literals (or output of JS console.log / Python dict repr with single quotes) into a JSON config, hand-writing config files, template engines emitting {key: value} without quoting.
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/8a9cc52515c5e97b.
Report an issue: GitHub.