{"record":{"id":"dedd41e2e19a3c8d","repo":"Yeachan-Heo/oh-my-codex","slug":"source-must-decode-to-a-json-object","errorCode":null,"errorMessage":"${source} must decode to a JSON object","messagePattern":"(.+?) must decode to a JSON object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/state.ts","lineNumber":62,"sourceCode":"}\n\nfunction parseStateInputJson(\n  raw: string,\n  source: '--input' | '--input-file',\n): Record<string, unknown> {\n  const json = source === '--input-file' && raw.startsWith('\\uFEFF') ? raw.slice(1) : raw;\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(json);\n  } catch (error) {\n    let message = `${source} must be valid JSON: ${(error as Error).message}`;\n    if (source === '--input' && looksLikeQuoteStrippedJson(raw)) {\n      message += WINDOWS_QUOTE_HINT;\n    }\n    throw new Error(message);\n  }\n  if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n    throw new Error(`${source} must decode to a JSON object`);\n  }\n  return { ...(parsed as Record<string, unknown>) };\n}\n\nexport async function stateCommand(\n  args: string[],\n  deps: StateCommandDependencies = {},\n): Promise<void> {\n  const stdout = deps.stdout ?? ((line: string) => console.log(line));\n  const stderr = deps.stderr ?? ((line: string) => console.error(line));\n  const execute = deps.execute ?? executeStateOperation;\n\n  const subcommand = args[0];\n  if (!subcommand || isHelpArg(subcommand)) {\n    stdout(STATE_HELP);\n    return;\n  }\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/cli/state.ts#L44-L80","documentation":"The JSON input parsed successfully but decoded to null, a primitive (string/number/boolean), or an array. The state command requires a top-level JSON object so it can spread keys into state.","triggerScenarios":"`state set --input '[1,2,3]'`, `--input '\"hello\"'`, or `--input 'null'`.","commonSituations":"Passing a JSON array from jq output (`jq '.items'`), or a scalar where an object was expected; API payloads nested one level too deep.","solutions":["Wrap the payload as an object: `{\"data\": <your array>}` if an array is what you have","Use `jq '{key: .}'` to construct an object"],"exampleFix":"# before\nstate set --input \"$(jq '.items' data.json)\"\n# after\nstate set --input \"$(jq '{items: .items}' data.json)\"","handlingStrategy":"type-guard","validationCode":"const parsed = JSON.parse(text);\nif (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n  throw new TypeError('state input must be a JSON object');\n}","typeGuard":"function isJsonObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["Pipe through `jq '{data: .}'` when your payload is an array","Validate payload shape at the producer side"],"tags":["cli","json","type-validation"],"backgroundTag":"json-schema-mismatch","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}