alibaba/nacos · warning · Error

${name} must be a JSON object

Error message

${name} must be a JSON object

What it means

Thrown by serializeOptionalObject() in agent-console-model when an optional JSON text field (e.g. extensions) is non-empty and parses successfully but is not a JSON object (it is an array or primitive). Optional object fields are allowed to be blank, but when present they must be a single JSON object.

Source

Thrown at console-ui/src/pages/AI/agent-console-model.js:290

  });
  const result = {
    protocol: required(editor.customProtocol, 'protocol'),
    protocolVersion: String(editor.customProtocolVersion || '').trim() || undefined,
    descriptorMediaType: required(editor.customDescriptorMediaType, 'descriptorMediaType'),
    nativeDescriptor,
    endpointSourceOrder: sourceOrder(editor.endpointSourceMode),
  };
  if (declaredEndpoints.length > 0) result.declaredEndpoints = declaredEndpoints;
  return result;
}

function serializeOptionalObject(value, name) {
  if (!String(value || '').trim()) {
    return undefined;
  }
  const parsed = parseJson(value, name);
  if (!isObject(parsed)) {
    throw new Error(`${name} must be a JSON object`);
  }
  return JSON.stringify(parsed);
}

function validateUniqueProtocols(callInterfaces) {
  const protocols = new Set();
  callInterfaces.forEach(callInterface => {
    if (protocols.has(callInterface.protocol)) {
      throw new Error(`protocol must be unique: ${callInterface.protocol}`);
    }
    protocols.add(callInterface.protocol);
  });
  return callInterfaces;
}

function serializeCallInterfaces(values, protocolEditors) {
  const agentName = required(values.agentName, 'agentName');
  const version = required(values.version, 'version');

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Leave the field empty if you do not need it.
  2. Enter a JSON object, e.g. {"key":"value"}.
  3. Move list-shaped data to a field that accepts arrays (like tags).

Example fix

// before
[1, 2, 3]

// after
{"custom":"value"}
Defensive patterns

Strategy: validation

Validate before calling

function isValidOptionalObject(text) {
  if (!String(text || '').trim()) return true;
  let p;
  try { p = JSON.parse(text); } catch { return false; }
  return p !== null && !Array.isArray(p) && typeof p === 'object';
}

Type guard

function isPlainObject(v) {
  return v !== null && !Array.isArray(v) && typeof v === 'object';
}

Try / catch

try {
  serializeOptionalObject(values.extensions, 'extensions');
} catch (e) {
  Message.error(e.message); // e.g. 'extensions must be a JSON object'
  return;
}

Prevention

When it happens

Trigger: Entering a JSON array or primitive into the 'extensions' field (or any other optional-object field) during initial agent draft creation, e.g. extensions = '[1,2]'.

Common situations: User treats an object field as a list field, or pastes an array where a map is required.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/f004e986321a260d. Report an issue: GitHub.