Yeachan-Heo/oh-my-codex · error · Error

--input must be valid JSON: ${(error as Error).message}

Error message

--input must be valid JSON: ${(error as Error).message}

What it means

Thrown when --input is present but its value fails JSON.parse; the parser's message is included. The question specification must deserialize before normalizeQuestionInput can process it.

Source

Thrown at src/cli/question.ts:298

        question_id: parsed.answerQuestionId,
        session_id: parsed.sessionId,
        error: {
          code,
          message: extractErrorMessage(error),
        },
      }, parsed.json);
      process.exitCode = 1;
    }
    return;
  }

  if (!parsed.input) throw new Error('omx question requires --input in normal mode');

  let rawInput: unknown;
  try {
    rawInput = JSON.parse(parsed.input);
  } catch (error) {
    throw new Error(`--input must be valid JSON: ${(error as Error).message}`);
  }

  const input = normalizeQuestionInput(rawInput);
  const cwd = process.cwd();
  const policy = await evaluateQuestionPolicy({
    cwd,
    explicitSessionId: input.session_id,
    questionSource: input.source,
  });
  if (!policy.allowed) {
    printJson({
      ok: false,
      error: {
        code: policy.code,
        message: policy.message,
      },
    }, parsed.json);
    process.exitCode = 1;

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Quote the whole document in single quotes and fix the reported syntax position
  2. Pipe the spec through `jq .` (or `jq -c .`) to validate and compact it first
  3. Generate the JSON with a tool instead of hand-writing it when it contains dynamic values

Example fix

# before
omx question --input "{question: 'Deploy?'}"
# after
omx question --input '{"question":"Deploy?"}'
Defensive patterns

Strategy: validation

Validate before calling

const inputJson = JSON.stringify(questionSpec); // guaranteed parseable
await questionCommand(['--input', inputJson]);

Try / catch

try {
  await runQuestion(input);
} catch (error) {
  if (error instanceof Error && error.message.includes('--input must be valid JSON')) {
    throw new Error(`question spec was not serialized as JSON: ${input}`);
  }
  throw error;
}

Prevention

When it happens

Trigger: `omx question --input <value>` where <value> contains invalid JSON — unquoted keys, trailing commas, or broken shell quoting that truncates the document.

Common situations: Writing JSON directly in a shell without outer single quotes, template variables that inject unescaped quotes, or hand-editing a long spec and leaving a trailing comma.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/775825bcea2f1ae9. Report an issue: GitHub.