nanocoai/nanoclaw · error · StdinJsonInputError
--stdin-json input is not valid JSON
Error message
--stdin-json input is not valid JSON
What it means
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.
Source
Thrown at src/cli/stdin-json.ts:72
throw new StdinJsonInputError(`--stdin-json input exceeds ${MAX_STDIN_JSON_BYTES} bytes`);
}
chunks.push(buffer);
}
return Buffer.concat(chunks, byteLength).toString('utf8');
}
/** Parse the input, requiring exactly one JSON object — not an array, scalar, or null. */
function parseJsonObject(source: string): Record<string, unknown> {
if (source.trim().length === 0) {
throw new StdinJsonInputError('--stdin-json input is empty');
}
let parsed: unknown;
try {
parsed = JSON.parse(source);
} catch (err) {
throw new StdinJsonInputError('--stdin-json input is not valid JSON', { cause: err });
}
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new StdinJsonInputError('--stdin-json input must be one JSON object');
}
return parsed as Record<string, unknown>;
}
/** Match the key normalization applied by command parsers in crud.ts. */
function canonicalArgKey(key: string): string {
return key.replace(/-/g, '_');
}
/**
* Reject any stdin key that could collide with another arg after the merge.
*
* Command parsers (crud.ts) normalize `-` to `_` in arg keys, so `group-id`View on GitHub (pinned to 294ef2aee8)
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
Example fix
# before
echo '{"name": "x",}' | ncl groups create --stdin-json
# after
echo '{"name": "x"}' | ncl groups create --stdin-json Defensive patterns
Strategy: try-catch
Validate before calling
try { JSON.parse(src); } catch { throw new Error('invalid JSON'); } Type guard
function parsesAsJson(s: string): boolean { try { JSON.parse(s); return true; } catch { return false; } } Try / catch
try { JSON.parse(source); } catch (err) { throw new StdinJsonInputError('--stdin-json input is not valid JSON', { cause: err }); } Prevention
- Generate JSON with jq or a serializer, not string concatenation
- Lint files with `jq . < file` before piping
When it happens
Trigger: Piping malformed JSON — trailing commas, comments, smart quotes, truncated files, or concatenated objects.
Common situations: Hand-written JSON in heredocs, JSON produced by echoing shell variables unquoted, or a truncated file.
Related errors
- --stdin-json input exceeds ${MAX_STDIN_JSON_BYTES} bytes
- --stdin-json input is empty
- --stdin-json input must be one JSON object
- --stdin-json key "__proto__" is not allowed
- --stdin-json key "${key}" is also supplied on argv
AI-assisted analysis of nanocoai/nanoclaw@294ef2aee8 (2026-08-28).
Data as JSON: /api/errors/c917671e2d1eb206.
Report an issue: GitHub.