CoplayDev/unity-mcp · error · JsonException
Failed to parse 'properties' JSON string. Raw value: {token}
Error message
Failed to parse 'properties' JSON string. Raw value: {token} What it means
ExtractProperties accepts the 'properties' field either as a JSON object or as a JSON-encoded string. When it is a string, JToken.Parse is attempted; if the string is not valid JSON a JsonException is thrown embedding the raw value.
Source
Thrown at MCPForUnity/Editor/Tools/Animation/ManageAnimation.cs:101
if (token == null || token.Type == JTokenType.Null)
{
return null;
}
if (token is JObject obj)
{
return obj;
}
if (token.Type == JTokenType.String)
{
try
{
return JToken.Parse(token.ToString()) as JObject;
}
catch (JsonException ex)
{
throw new JsonException(
$"Failed to parse 'properties' JSON string. Raw value: {token}",
ex);
}
}
return null;
}
private static string NormalizeKey(string key, bool allowAliases)
{
if (string.IsNullOrEmpty(key))
{
return key;
}
if (string.Equals(key, "action", StringComparison.OrdinalIgnoreCase))
{
return "action";
}View on GitHub (pinned to c21bf496bc)
Solutions
- Pass 'properties' as a JSON object directly, not as a string.
- If it must be a string, ensure it is valid JSON (quoted keys, proper braces).
- Validate the payload with a JSON parser before sending.
Example fix
// before
{ "action": "set", "properties": "scale,rotation" }
// after
{ "action": "set", "properties": { "scale": 1.0, "rotation": 0 } } Defensive patterns
Strategy: type-guard
Validate before calling
if (payload.TryGetValue("properties", out var t) && t.Type == JTokenType.String)
{
if (!IsValidJson(t.ToString()))
throw new ArgumentException("'properties' string must be valid JSON.");
}
// bool IsValidJson(string s) => try { JToken.Parse(s); return true; } catch { return false; } Type guard
// Pass properties as a JSON object, not a string:
// valid: { "properties": { "scale": 1.0 } }
// valid: { "properties": "{ \"scale\": 1.0 }" } (JSON-encoded string)
// invalid:{ "properties": "scale,rotation" } Prevention
- Send 'properties' as a JSON object whenever possible.
- If sending a string, validate it parses as JSON before dispatch.
- Document the accepted shapes in the tool's schema for LLM callers.
When it happens
Trigger: An AI assistant or caller sends 'properties' as a plain delimited string ('scale,rotation'), malformed JSON ('{scale: 1}' in some strict parsers), or a truncated JSON fragment; double-encoding produced a non-JSON string.
Common situations: LLM formats the field as CSV instead of JSON; a serialization layer double-encoded the object; manual payload construction with a syntax error.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Color array must have 3 or 4 elements.
- Failed to parse float at index {i}: '{arr[i]}'
- Failed to parse 'properties' JSON string. Raw value: {token}
- set-pixels must be a JSON object
- import_settings must be a JSON object
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/b141151325a545fe.
Report an issue: GitHub.