alibaba/nacos · warning · Error
Labels must be a JSON object
Error message
Labels must be a JSON object
What it means
Thrown by the Agent Detail page when the user-submitted labels text parses as valid JSON but is not a plain object (it is an array, a primitive, or null). Labels on an AI agent version must be a JSON object map. The validator runs JSON.parse then explicitly rejects arrays and non-objects.
Source
Thrown at console-ui/src/pages/AI/AgentDetail/AgentDetail.js:279
version: versionDetail.version,
})
.then(() => {
Message.success('Draft deleted');
this.setState({ selectedVersion: '', versionDetail: null }, () => {
this.loadOverview();
this.loadVersions(1);
});
})
.catch(error => Message.error(error.message))
.finally(() => this.setState({ actionLoading: false }));
};
updateLabels = () => {
let labels;
try {
labels = JSON.parse(this.state.labelsText);
if (!labels || Array.isArray(labels) || typeof labels !== 'object') {
throw new Error('Labels must be a JSON object');
}
if (Object.prototype.hasOwnProperty.call(labels, 'latest')) {
throw new Error('The latest label is managed by the server');
}
} catch (error) {
Message.error(error.message);
return;
}
agentApi
.updateLabels({
namespaceId: this.namespaceId(),
agentName: this.agentName(),
labels: JSON.stringify(labels),
})
.then(() => {
Message.success('Labels updated');
this.loadOverview();
})View on GitHub (pinned to 9b989acdf1)
Solutions
- Enter labels as a JSON object, e.g. {"env":"prod","team":"core"}.
- Leave the labels field empty if no custom labels are needed.
- If you need a list, use the tags field instead, not labels.
Example fix
// before
[{"env":"prod"}]
// after
{"env":"prod"} Defensive patterns
Strategy: validation
Validate before calling
function isValidLabelsObject(text) {
let obj;
try { obj = JSON.parse(text); } catch { return false; }
return !!obj && !Array.isArray(obj) && typeof obj === 'object';
} Type guard
function isPlainObject(v) {
return v !== null && !Array.isArray(v) && typeof v === 'object';
} Try / catch
try {
const labels = JSON.parse(this.state.labelsText);
if (!isPlainObject(labels)) { Message.error('Labels must be a JSON object'); return; }
} catch (e) { Message.error('Labels must be valid JSON'); return; } Prevention
- Document that labels is a key/value map, not a list.
- Provide a JSON object template/placeholder in the labels input.
- Validate on blur, not only on submit, for earlier feedback.
When it happens
Trigger: Entering labels as a JSON array like ["a","b"] or a bare string/number instead of an object in the Agent Detail labels editor, then clicking update.
Common situations: Developers confuse labels (key/value map) with tags (array). Copy-pasting a JSON array from another field.
Related errors
- The latest label is managed by the server
- ${name} must be valid JSON
- ${name} must be a JSON object
- callInterfaces must be a non-empty JSON array
- agent.labelsObjectRequired
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/5485debc2e07de3c.
Report an issue: GitHub.