alibaba/spring-ai-alibaba · error · RuntimeException

Nacos config content is not valid JSON, but dot notation was

Error message

Nacos config content is not valid JSON, but dot notation was used. Please ensure the config is in JSON format or remove the dot notation. Content: <jsonString>

What it means

Thrown by NacosMcpGatewayToolCallback.extractJsonValueFromNacos when a dot-notation path is applied to Nacos config content that cannot be parsed as JSON (JsonProcessingException). The error tells you the referenced config is not JSON, which dot-notation extraction requires; the full content is included in the message.

Source

Thrown at spring-boot-starters/spring-ai-alibaba-starter-config-nacos/src/main/java/com/alibaba/cloud/ai/agent/nacos/tools/NacosMcpGatewayToolCallback.java:258

			// 根据节点类型返回合适的值
			if (currentNode.isTextual()) {
				return currentNode.asText();
			}
			else if (currentNode.isNumber()) {
				return currentNode.asText();
			}
			else if (currentNode.isBoolean()) {
				return String.valueOf(currentNode.asBoolean());
			}
			else {
				// 对于复杂对象,返回JSON字符串
				return currentNode.toString();
			}
		}
		catch (JsonProcessingException e) {
			logger.error("[extractJsonValueFromNacos] Failed to parse JSON from Nacos config. Content: {}, Error: {}",
					jsonString, e.getMessage());
			throw new RuntimeException(
					"Nacos config content is not valid JSON, but dot notation was used. Please ensure the config is in JSON format or remove the dot notation. Content: "
							+ jsonString,
					e);
		}
		catch (Exception e) {
			logger.error("[extractJsonValueFromNacos] Failed to extract JSON value from Nacos config: {}",
					e.getMessage(), e);
			throw e;
		}
	}

	private String processTemplateString(String template, Map<String, Object> params) {
		Map<String, Object> args = (Map<String, Object>) params.get("args");
		String extendedData = (String) params.get("extendedData");
		logger.debug("[processTemplateString] template: {} args: {} extendedData: {}", template, args, extendedData);
		if (template == null || template.isEmpty()) {
			return "";
		}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Re-publish the Nacos config content as valid JSON (check the message for the offending content).
  2. Remove the dot notation from the placeholder if you only need the raw config text.
  3. Validate the config with a JSON parser (e.g. jq) before publishing.
  4. Strip BOM/whitespace from the stored config if it visually looks like JSON but fails to parse.

Example fix

// before (Nacos content)
user.name=alice
user.role=admin
// after: publish JSON for dot-notation access
{"user": {"name": "alice", "role": "admin"}}
Defensive patterns

Strategy: validation

Validate before calling

boolean isJson(String s) {
    try { new ObjectMapper().readTree(s); return true; } catch (Exception e) { return false; }
}
// verify the Nacos config parses as JSON before using dot notation
// assert isJson(nacosConfigContent);

Try / catch

try {
    return callback.call(input);
} catch (RuntimeException e) {
    if (e.getMessage().contains("Nacos config content is not valid JSON")) {
        logger.error("Re-publish config as JSON or drop dot notation; content was: {}", e.getMessage());
    }
    throw e;
}

Prevention

When it happens

Trigger: A placeholder uses dot notation like ${ref:a.b.c} but the Nacos config content for the dataId/group is properties/YAML/plain text, so ObjectMapper fails with JsonProcessingException during extraction.

Common situations: Config published to Nacos as .properties while the tool template assumes JSON; accidental trailing characters or BOM breaking JSON; users switching config format without updating placeholders.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/90679dd0a5cffcff. Report an issue: GitHub.