apple/pkl · error · ParseException

':'

Error message

':'

What it means

While parsing a JSON object, after reading a member name the parser requires a colon separating the name from its value. readObject calls readChar(':') and, if the next non-whitespace character is not ':', throws this ParseException (via expected(":")) with line/column position information. It indicates malformed JSON: a missing colon between an object key and its value.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/util/json/JsonParser.java:188

    var object = handler.startObject();
    read();
    if (++nestingLevel > MAX_NESTING_LEVEL) {
      throw error("Nesting too deep");
    }
    skipWhiteSpace();
    if (readChar('}')) {
      nestingLevel--;
      handler.endObject(object);
      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");
    }

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Validate the JSON with a linter/formatter before parsing; fix the location the ParseException reports (missing ':' after the object key).
  2. Quote object keys and separate them from values with ':' — strict JSON requires {"key": value}, not {key: value}.
  3. If the source is JS-object-like text, convert it to strict JSON first (e.g. JSON5/Hjson parser or manual quoting).
  4. Catch ParseException and surface its position so the offending spot in the input can be corrected quickly.

Example fix

// before
String json = "{name \"pkl\"}"; // missing ':'
// after
String json = "{\"name\": \"pkl\"}";
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate with a strict JSON parser before use
try {
  new jakarta.json.Json().createReader(new StringReader(json)).read();
} catch (Exception e) {
  throw new IllegalArgumentException("Not strict JSON: " + e.getMessage());
}

Try / catch

try {
  parser.parse(json);
} catch (ParseException e) {
  throw new IllegalArgumentException("Malformed JSON at line " + e.getLocation().line + ", column " + e.getLocation().column + ": " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: parse(String) / parse(Reader) on JSON like "{\"a\" 1}" or "{key: 1}" (key not quoted, no colon). Specifically: readName succeeded, then the next character was not ':'.

Common situations: Hand-written or templated JSON where the colon was dropped, JSON5/JavaScript-style object literals ({key: 1} with unquoted keys) pasted into a context requiring strict JSON, string concatenation that mangles members, or edits to generated config files.

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/f3c5c0e8cc4b8db1. Report an issue: GitHub.