can1357/oh-my-pi · error · SyntaxError
Expected value after ':'
Error message
Expected value after ':'
What it means
Thrown by RelaxedJson.#object in strict mode when a ':' was consumed but end-of-input is reached before any value follows. The key/value pair cannot be completed, so strict mode refuses the input; partial mode would return the object parsed so far.
Source
Thrown at packages/utils/src/json-parse.ts:283
}
if (c === ",") {
// Tolerate leading / doubled / trailing commas.
this.#i++;
continue;
}
const key = this.#key();
this.#ws();
if (this.#i < this.#n && this.#s[this.#i] === ":") {
this.#i++;
} else if (this.#partial) {
return out;
} else {
throw new SyntaxError("Expected ':' in object");
}
this.#ws();
if (this.#i >= this.#n) {
if (this.#partial) return out;
throw new SyntaxError("Expected value after ':'");
}
const value = this.#value(true);
if (value === INCOMPLETE) return out;
out[key] = value;
this.#ws();
const d = this.#i < this.#n ? this.#s[this.#i] : "";
if (d === ",") {
this.#i++;
continue;
}
if (d === "}") {
this.#i++;
return out;
}
if (this.#partial) return out;
throw new SyntaxError("Expected ',' or '}' in object");
}
}View on GitHub (pinned to 9690622007)
Solutions
- Ensure the full payload is read before parsing (await the stream/file completion)
- Use parseStreamingJson for genuinely incomplete input — it auto-closes and returns the partial object
- Use classifyJsonPrefix to know the buffer is still a 'prefix' and wait for more deltas before final parsing
Example fix
// before
const v = parseJsonWithRepair(`{"a":`); // SyntaxError: Expected value after ':'
// after
const v = parseStreamingJson(`{"a":`); // {} (partial-safe) Defensive patterns
Strategy: validation
Validate before calling
import { classifyJsonPrefix } from "@oh-my-pi/pi-utils/json-parse";
if (classifyJsonPrefix(text) !== "complete") {
// input still incomplete (e.g. ends after ':') — do not final-parse yet
} Try / catch
try {
const value = parseJsonWithRepair<T>(text);
} catch (err) {
if (err instanceof SyntaxError && err.message === "Expected value after ':'") {
const partial = parseStreamingJson<T>(text); // returns object parsed so far
} else throw err;
} Prevention
- Wait for stream completion before final-parsing
- Use parseStreamingJson/parseStreamingJsonThrottled for streaming tool-call buffers
- Check content-length / stream end events before treating a buffer as final
When it happens
Trigger: parseJsonWithRepair with input ending right after a colon: '{"a":' or '{"a": '. Occurs whenever a truncated payload happens to cut exactly between the colon and the value.
Common situations: LLM tool-call argument stream truncated mid-pair; a fixed-size read that cut the payload; log capture that clipped the buffer.
Related errors
- Unterminated object
- Expected ':' in object
- Expected ',' or '}' in object
- Unterminated array
- Unterminated string
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/ea14f0f19de21983.
Report an issue: GitHub.