{"record":{"id":"c917671e2d1eb206","repo":"nanocoai/nanoclaw","slug":"stdin-json-input-is-not-valid-json-c91767","errorCode":null,"errorMessage":"--stdin-json input is not valid JSON","messagePattern":"--stdin-json input is not valid JSON","errorType":"validation","errorClass":"StdinJsonInputError","httpStatus":null,"severity":"error","filePath":"src/cli/stdin-json.ts","lineNumber":72,"sourceCode":"      throw new StdinJsonInputError(`--stdin-json input exceeds ${MAX_STDIN_JSON_BYTES} bytes`);\n    }\n    chunks.push(buffer);\n  }\n\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`","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/nanocoai/nanoclaw/blob/294ef2aee85218b23ad30eda9dfe10e590b54a8c/src/cli/stdin-json.ts#L54-L90","documentation":"JSON.parse of the --stdin-json input failed; the underlying SyntaxError is attached as {cause}. The input must be a single syntactically valid JSON document.","triggerScenarios":"Piping malformed JSON — trailing commas, comments, smart quotes, truncated files, or concatenated objects.","commonSituations":"Hand-written JSON in heredocs, JSON produced by echoing shell variables unquoted, or a truncated file.","solutions":["Validate with a JSON linter or `jq . < file` first","Regenerate the file programmatically instead of hand-editing","Fix the reported syntax error position from the cause"],"exampleFix":"# before\necho '{\"name\": \"x\",}' | ncl groups create --stdin-json\n# after\necho '{\"name\": \"x\"}' | ncl groups create --stdin-json","handlingStrategy":"try-catch","validationCode":"try { JSON.parse(src); } catch { throw new Error('invalid JSON'); }","typeGuard":"function parsesAsJson(s: string): boolean { try { JSON.parse(s); return true; } catch { return false; } }","tryCatchPattern":"try { JSON.parse(source); } catch (err) { throw new StdinJsonInputError('--stdin-json input is not valid JSON', { cause: err }); }","preventionTips":["Generate JSON with jq or a serializer, not string concatenation","Lint files with `jq . < file` before piping"],"tags":["cli","stdin-json","json-parse"],"backgroundTag":"invalid-json","analyzedSha":"294ef2aee85218b23ad30eda9dfe10e590b54a8c","analyzedAt":"2026-08-28T13:59:10.357Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}