alibaba/nacos · error · Error
${name} must be valid JSON
Error message
${name} must be valid JSON What it means
Generic JSON validator in the new-agent console model. Wraps JSON.parse in a try/catch and throws this error (not a SyntaxError) when parsing fails. Used for fields like nativeDescriptor, agentCard, callInterfaces, and any object-typed field parsed via parseJson/parseAgentCardJson.
Source
Thrown at console-ui-next/src/pages/newAgent/agent-console-model.ts:115
callInterfaces: string;
basedOnVersion: string;
author: string;
changeDescription: string;
}
function required(value: string, name: string): string {
const result = value.trim();
if (!result) {
throw new Error(`${name} is required`);
}
return result;
}
function parseJson(value: string, name: string): unknown {
try {
return JSON.parse(value);
} catch {
throw new Error(`${name} must be valid JSON`);
}
}
function parseAgentCardJson(value: string): unknown {
const withoutTrailingCommas = value.replace(
/("(?:\\.|[^"\\])*")|,\s*([}\]])/g,
(match, quoted, closing) => quoted || closing || match,
);
return parseJson(withoutTrailingCommas, 'agentCard');
}
function isObject(value: unknown): value is Record<string, unknown> {
return value !== null && !Array.isArray(value) && typeof value === 'object';
}
function optionalString(value: unknown): string | undefined {
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
}View on GitHub (pinned to 9b989acdf1)
Solutions
- Run the JSON through a linter (jsonlint) or use a JSON editor component with validation.
- Use double quotes for all keys and string values; remove trailing commas (except for agentCard where they are auto-stripped).
- Replace single quotes with double quotes; ensure strings are fully closed.
Example fix
// before
{name: 'my-agent',}
// after
{"name":"my-agent"} Defensive patterns
Strategy: validation
Validate before calling
function safeJsonParse(text, name) {
try { return JSON.parse(text); } catch { throw new Error(`${name} must be valid JSON`); }
} Type guard
function isValidJson(text: string): boolean {
try { JSON.parse(text); return true; } catch { return false; }
} Try / catch
try { parseJson(value, 'nativeDescriptor'); } catch (e) {
if (/must be valid JSON/.test(e.message)) { toast.error('Fix the JSON syntax'); }
} Prevention
- Use a JSON editor component
- Lint on blur
- Replace single quotes with double quotes
When it happens
Trigger: User enters a malformed JSON string in a JSON-typed field: trailing comma, unquoted keys, single quotes, or unterminated string. Note parseAgentCardJson strips trailing commas before calling parseJson, so trailing-comma agentCard input is tolerated.
Common situations: Hand-editing JSON in a textarea without schema assistance. Copy-paste from a JS object literal (unquoted keys, single quotes). Non-ASCII smart quotes breaking the parse.
Related errors
- Invalid JSON/YAML format
- ${name} must be a JSON object
- 20002
- PARAMETER_MISSING
- Agent Version storage descriptor must be a JSON object
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/20dfb84224f38907.
Report an issue: GitHub.