{"record":{"id":"608d7095cdbbb0cf","repo":"nanocoai/nanoclaw","slug":"stdin-json-input-must-be-one-json-object-608d70","errorCode":null,"errorMessage":"--stdin-json input must be one JSON object","messagePattern":"--stdin-json input must be one JSON object","errorType":"validation","errorClass":"StdinJsonInputError","httpStatus":null,"severity":"error","filePath":"src/cli/stdin-json.ts","lineNumber":76,"sourceCode":"\n  return Buffer.concat(chunks, byteLength).toString('utf8');\n}\n\n/** Parse the input, requiring exactly one JSON object — not an array, scalar, or null. */\nfunction parseJsonObject(source: string): Record<string, unknown> {\n  if (source.trim().length === 0) {\n    throw new StdinJsonInputError('--stdin-json input is empty');\n  }\n\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(source);\n  } catch (err) {\n    throw new StdinJsonInputError('--stdin-json input is not valid JSON', { cause: err });\n  }\n\n  if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n    throw new StdinJsonInputError('--stdin-json input must be one JSON object');\n  }\n\n  return parsed as Record<string, unknown>;\n}\n\n/** Match the key normalization applied by command parsers in crud.ts. */\nfunction canonicalArgKey(key: string): string {\n  return key.replace(/-/g, '_');\n}\n\n/**\n * Reject any stdin key that could collide with another arg after the merge.\n *\n * Command parsers (crud.ts) normalize `-` to `_` in arg keys, so `group-id`\n * and `group_id` are the same argument downstream. Two keys that are distinct\n * here but identical after normalization would silently overwrite each other\n * past this point — so every such alias is a hard conflict, whether the pair\n * is stdin-vs-argv or two stdin keys.","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/nanocoai/nanoclaw/blob/294ef2aee85218b23ad30eda9dfe10e590b54a8c/src/cli/stdin-json.ts#L58-L94","documentation":"The --stdin-json input parsed successfully but is not a single JSON object — arrays, scalars, null, and non-objects are rejected because args must be a key/value map.","triggerScenarios":"Piping `[...]`, `\"string\"`, `42`, `true`, or `null` to --stdin-json.","commonSituations":"Piping a JSON array of records expecting batch create, or a jq filter that emits a scalar/string.","solutions":["Wrap the data in an object with the intended argument keys","For arrays, loop in shell and invoke the command per element"],"exampleFix":"# before\necho '[{\"name\":\"a\"},{\"name\":\"b\"}]' | ncl groups create --stdin-json\n# after\nfor n in a b; do echo \"{\\\"name\\\":\\\"$n\\\"}\" | ncl groups create --stdin-json; done","handlingStrategy":"type-guard","validationCode":"const obj = JSON.parse(src);\nif (Array.isArray(obj) || typeof obj !== 'object' || obj === null) throw new Error('need one object');","typeGuard":"function isJsonObject(x: unknown): x is Record<string, unknown> {\n  return typeof x === 'object' && x !== null && !Array.isArray(x);\n}","tryCatchPattern":null,"preventionTips":["Wrap batch items in a loop of single-object invocations"],"tags":["cli","stdin-json","type-validation"],"backgroundTag":"invalid-request-payload","analyzedSha":"294ef2aee85218b23ad30eda9dfe10e590b54a8c","analyzedAt":"2026-08-28T13:59:10.357Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}