paperclipai/paperclip · error
Invalid JSON
Error message
Invalid JSON: ${err instanceof Error ? err.message : String(err)} What it means
parseOptionalJson wraps JSON.parse for --metadata-style options and rethrows parse failures with the parser's message; the input string is not valid JSON. This is a generic JSON-parse guard.
Solutions
- Fix the JSON input; validate it with `jq` or a JSON linter before re-running.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cli/src/commands/client/project.ts:226 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of paperclipai/paperclip@120ae5428f (2026-08-18).
Data as JSON: /api/errors/e2fbc0dbe8e18c76.
Report an issue: GitHub.
Appendix: source
Thrown at cli/src/commands/client/project.ts:226
}
function parseCsv(value: string | undefined): string[] | undefined {
if (value === undefined) return undefined;
return value.split(",").map((part) => part.trim()).filter(Boolean);
}
function parseNullableString(value: string | undefined): string | null | undefined {
if (value === undefined) return undefined;
return value.trim().toLowerCase() === "null" ? null : value;
}
function parseOptionalJson(value: string | undefined): unknown {
if (value === undefined) return undefined;
if (value.trim().toLowerCase() === "null") return null;
try {
return JSON.parse(value);
} catch (err) {
throw new Error(`Invalid JSON: ${err instanceof Error ? err.message : String(err)}`);
}
}
View on GitHub (pinned to 120ae5428f)