can1357/oh-my-pi · error · SyntaxError

Expected ':' in object

Error message

Expected ':' in object

What it means

Thrown by RelaxedJson.#object in strict mode after parsing an object key when the next character is not ':' and end-of-input was not reached. Even this relaxed parser requires a colon between key and value; in partial mode it bails out with the object parsed so far instead of throwing.

Source

Thrown at packages/utils/src/json-parse.ts:278

			}
			const c = this.#s[this.#i];
			if (c === "}") {
				this.#i++;
				return out;
			}
			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;

View on GitHub (pinned to 9690622007)

Solutions

  1. Fix the input so every key is followed by ':' before its value
  2. Use parseStreamingJson if the input may be an incomplete prefix (it returns the partial object instead of throwing)
  3. Run repairJson first if raw control characters or bad escapes are corrupting the structure (a bad escape can make the parser misjudge key boundaries)
  4. Log the raw input around the failing key and regenerate the JSON from the producing system

Example fix

// before
const v = parseJsonWithRepair(`{"a" 1}`); // SyntaxError: Expected ':' in object
// after
const v = parseJsonWithRepair(`{"a": 1}`); // {a: 1}
Defensive patterns

Strategy: validation

Validate before calling

// Sanity-check object structure before parsing: every key must be followed by ':'
const ok = /^\s*\{.*\}\s*$/s.test(text) && !/['"]?\w+['"]?\s+[^:,}\s]/.test(text.replace(/"(\\.|[^"\\])*"/g, '"S"'));

Try / catch

try {
  const value = parseJsonWithRepair<T>(text);
} catch (err) {
  if (err instanceof SyntaxError && err.message === "Expected ':' in object") {
    // reject or regenerate the malformed payload; log the raw text for diagnosis
  } else throw err;
}

Prevention

When it happens

Trigger: parseJsonWithRepair with '{"a" 1}', '{a; b}', or a key followed directly by another key '{"a" "b": 1}' — i.e. a missing or malformed ':' separator in strict mode.

Common situations: Hand-written or template-generated JSON missing the colon; an LLM emitting YAML-ish 'key value' pairs instead of JSON; a copy/paste that dropped the ':' character.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/d4d9b20c17b85733. Report an issue: GitHub.