{"record":{"id":"775825bcea2f1ae9","repo":"Yeachan-Heo/oh-my-codex","slug":"input-must-be-valid-json-error-as-error-mes","errorCode":null,"errorMessage":"--input must be valid JSON: ${(error as Error).message}","messagePattern":"--input must be valid JSON: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cli/question.ts","lineNumber":298,"sourceCode":"        question_id: parsed.answerQuestionId,\n        session_id: parsed.sessionId,\n        error: {\n          code,\n          message: extractErrorMessage(error),\n        },\n      }, parsed.json);\n      process.exitCode = 1;\n    }\n    return;\n  }\n\n  if (!parsed.input) throw new Error('omx question requires --input in normal mode');\n\n  let rawInput: unknown;\n  try {\n    rawInput = JSON.parse(parsed.input);\n  } catch (error) {\n    throw new Error(`--input must be valid JSON: ${(error as Error).message}`);\n  }\n\n  const input = normalizeQuestionInput(rawInput);\n  const cwd = process.cwd();\n  const policy = await evaluateQuestionPolicy({\n    cwd,\n    explicitSessionId: input.session_id,\n    questionSource: input.source,\n  });\n  if (!policy.allowed) {\n    printJson({\n      ok: false,\n      error: {\n        code: policy.code,\n        message: policy.message,\n      },\n    }, parsed.json);\n    process.exitCode = 1;","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/cli/question.ts#L280-L316","documentation":"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.","triggerScenarios":"`omx question --input <value>` where <value> contains invalid JSON — unquoted keys, trailing commas, or broken shell quoting that truncates the document.","commonSituations":"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.","solutions":["Quote the whole document in single quotes and fix the reported syntax position","Pipe the spec through `jq .` (or `jq -c .`) to validate and compact it first","Generate the JSON with a tool instead of hand-writing it when it contains dynamic values"],"exampleFix":"# before\nomx question --input \"{question: 'Deploy?'}\"\n# after\nomx question --input '{\"question\":\"Deploy?\"}'","handlingStrategy":"validation","validationCode":"const inputJson = JSON.stringify(questionSpec); // guaranteed parseable\nawait questionCommand(['--input', inputJson]);","typeGuard":null,"tryCatchPattern":"try {\n  await runQuestion(input);\n} catch (error) {\n  if (error instanceof Error && error.message.includes('--input must be valid JSON')) {\n    throw new Error(`question spec was not serialized as JSON: ${input}`);\n  }\n  throw error;\n}","preventionTips":["Always serialize with JSON.stringify rather than hand-writing JSON in templates","Lint dynamic specs through jq or JSON.parse before invoking","Avoid shell interpolation of raw strings into JSON"],"tags":["cli","json-parse","question","validation"],"backgroundTag":"invalid-json-input","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}