Yeachan-Heo/oh-my-codex · error · Error
Invalid --input JSON: ${error instanceof Error ? error.messa
Error message
Invalid --input JSON: ${error instanceof Error ? error.message : String(error)} What it means
Thrown by the catch in parseTeamApiArgs when the token after `--input` fails JSON.parse (syntax error). The original parser message is appended so you can see exactly where the JSON is malformed.
Source
Thrown at src/cli/team.ts:546
let input: Record<string, unknown> = {};
let json = false;
for (let i = 1; i < args.length; i += 1) {
const token = args[i];
if (token === '--json') {
json = true;
continue;
}
if (token === '--input') {
const next = args[i + 1];
if (!next) throw new Error('Missing value after --input');
try {
const parsed = JSON.parse(next) as unknown;
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new Error('input must be a JSON object');
}
input = parsed as Record<string, unknown>;
} catch (error) {
throw new Error(`Invalid --input JSON: ${error instanceof Error ? error.message : String(error)}`);
}
i += 1;
continue;
}
if (token.startsWith('--input=')) {
const raw = token.slice('--input='.length);
try {
const parsed = JSON.parse(raw) as unknown;
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new Error('input must be a JSON object');
}
input = parsed as Record<string, unknown>;
} catch (error) {
throw new Error(`Invalid --input JSON: ${error instanceof Error ? error.message : String(error)}`);
}
continue;
}
throw new Error(`Unknown argument for "omx team api": ${token}`);View on GitHub (pinned to 3ad79a8a6f)
Solutions
- Validate the payload with a JSON linter or `echo '<json>' | jq .` before running the command.
- Use single quotes around the JSON in POSIX shells and avoid single quotes inside, or escape properly.
- Prefer writing the JSON to a file and using shell substitution, or the --input= form, to reduce quoting issues.
Example fix
# before
omx team api create --input '{name:"acme"}'
# after
omx team api create --input '{"name":"acme"}' Defensive patterns
Strategy: try-catch
Validate before calling
try { JSON.parse(inputJson); } catch (e) {
console.error(`Payload is not valid JSON: ${e instanceof Error ? e.message : e}`);
process.exit(2);
} Type guard
function isParsableJson(s: string): boolean {
try { JSON.parse(s); return true; } catch { return false; }
} Try / catch
try { await teamApi(args); } catch (e) {
if (e instanceof Error && e.message.startsWith('Invalid --input JSON')) { /* surface parser detail, fix quoting */ }
else throw e;
} Prevention
- Single-quote the JSON in POSIX shells; never let the shell re-parse inner double quotes.
- Validate with `jq -c .` before passing.
When it happens
Trigger: `--input '{name:acme}'` (unquoted keys), trailing commas, unescaped quotes broken by shell quoting, or truncated JSON.
Common situations: Shell single/double-quote mangling of the JSON string, hand-typing JSON without quoting keys, or copy-paste truncation.
Related errors
- --answer must be valid JSON: ${(error as Error).message}
- --input must be valid JSON: ${(error as Error).message}
- Unknown adapt argument: ${arg}
- Unknown adapt target: ${target}. Supported targets: ${suppor
- Unknown adapt subcommand: ${subcommand}. Supported subcomman
AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27).
Data as JSON: /api/errors/cd63a22bd6f32024.
Report an issue: GitHub.