{"record":{"id":"2efbf1b746579534","repo":"alibaba/nacos","slug":"name-must-be-valid-json","errorCode":null,"errorMessage":"${name} must be valid JSON","messagePattern":"(.+?) must be valid JSON","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"console-ui/src/pages/AI/agent-console-model.js","lineNumber":65,"sourceCode":"    },\n  ],\n  null,\n  2\n);\n\nfunction required(value, name) {\n  const result = String(value || '').trim();\n  if (!result) {\n    throw new Error(`${name} is required`);\n  }\n  return result;\n}\n\nfunction parseJson(value, name) {\n  try {\n    return JSON.parse(value);\n  } catch (e) {\n    throw new Error(`${name} must be valid JSON`);\n  }\n}\n\nfunction parseAgentCardJson(value) {\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) {\n  return value !== null && !Array.isArray(value) && typeof value === 'object';\n}\n\nfunction optionalString(value) {\n  return typeof value === 'string' && value.trim() ? value.trim() : undefined;\n}","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console-ui/src/pages/AI/agent-console-model.js#L47-L83","documentation":"Thrown by the agent-console-model parseJson() helper when JSON.parse fails on a user-supplied text value. This guards every JSON text field (agentCard, callInterfaces, extensions, etc.). The error embeds the field name so you know which input is invalid.","triggerScenarios":"Entering malformed JSON in any agent text field: missing quotes, trailing characters, unbalanced braces. Note parseAgentCardJson tolerates trailing commas before parsing, so plain trailing commas alone will not trigger this.","commonSituations":"Hand-editing the AgentCard or callInterfaces JSON and introducing a syntax error; pasting JSON from a source that uses single quotes or comments.","solutions":["Validate the JSON in an external linter before pasting.","Use double quotes for all keys and string values.","If the only issue is trailing commas, they are already tolerated; look for a different syntax error."],"exampleFix":"// before\n{name: 'x',}\n\n// after\n{\"name\":\"x\"}","handlingStrategy":"validation","validationCode":"function isValidJson(text) {\n  try { JSON.parse(text); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  parseJson(values.extensions, 'extensions');\n} catch (e) {\n  Message.error(e.message); // e.g. 'extensions must be valid JSON'\n  return;\n}","preventionTips":["Provide a JSON editor with syntax highlighting and live validation.","Validate JSON on blur, not only on submit.","Offer a 'format JSON' button to catch errors early."],"tags":["validation","json","agent","frontend"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}