{"record":{"id":"20dfb84224f38907","repo":"alibaba/nacos","slug":"name-must-be-valid-json-20dfb8","errorCode":null,"errorMessage":"${name} must be valid JSON","messagePattern":"(.+?) must be valid JSON","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"console-ui-next/src/pages/newAgent/agent-console-model.ts","lineNumber":115,"sourceCode":"  callInterfaces: string;\n  basedOnVersion: string;\n  author: string;\n  changeDescription: string;\n}\n\nfunction required(value: string, name: string): string {\n  const result = value.trim();\n  if (!result) {\n    throw new Error(`${name} is required`);\n  }\n  return result;\n}\n\nfunction parseJson(value: string, name: string): unknown {\n  try {\n    return JSON.parse(value);\n  } catch {\n    throw new Error(`${name} must be valid JSON`);\n  }\n}\n\nfunction parseAgentCardJson(value: string): unknown {\n  const withoutTrailingCommas = value.replace(\n    /(\"(?:\\\\.|[^\"\\\\])*\")|,\\s*([}\\]])/g,\n    (match, quoted, closing) => quoted || closing || match,\n  );\n  return parseJson(withoutTrailingCommas, 'agentCard');\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n  return value !== null && !Array.isArray(value) && typeof value === 'object';\n}\n\nfunction optionalString(value: unknown): string | undefined {\n  return typeof value === 'string' && value.trim() ? value.trim() : undefined;\n}","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console-ui-next/src/pages/newAgent/agent-console-model.ts#L97-L133","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n{name: 'my-agent',}\n\n// after\n{\"name\":\"my-agent\"}","handlingStrategy":"validation","validationCode":"function safeJsonParse(text, name) {\n  try { return JSON.parse(text); } catch { throw new Error(`${name} must be valid JSON`); }\n}","typeGuard":"function isValidJson(text: string): boolean {\n  try { JSON.parse(text); return true; } catch { return false; }\n}","tryCatchPattern":"try { parseJson(value, 'nativeDescriptor'); } catch (e) {\n  if (/must be valid JSON/.test(e.message)) { toast.error('Fix the JSON syntax'); }\n}","preventionTips":["Use a JSON editor component","Lint on blur","Replace single quotes with double quotes"],"tags":["validation","json","parsing","form"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}