Unity-Technologies/UnityCsReference · error · JSONParseException
Invalid token at {}
Error message
Invalid token at {} What it means
Thrown by ParseConstant when a JSON literal token's four-character lookahead does not match 'true', 'fals' (prefix of 'false'), or 'null'. The parser reads four characters expecting a constant keyword; if none match, this error fires. It means the JSON contains an identifier-like token that is not a valid JSON keyword.
Source
Thrown at Editor/Mono/AssetStore/Json.cs:674
c = "" + cur + Next() + Next() + Next();
Next();
if (c == "true")
{
return new JSONValue(true);
}
else if (c == "fals")
{
if (cur == 'e')
{
Next();
return new JSONValue(false);
}
}
else if (c == "null")
{
return new JSONValue(null);
}
throw new JSONParseException("Invalid token at " + PosMsg());
}
}
}
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Check the JSON at the reported position for non-standard literal values (True instead of true, None instead of null, etc.).
- Ensure the data producer serializes using a standard JSON library rather than manual string building.
- If the source is under your control, replace capitalized or non-standard literals with lowercase JSON equivalents.
- Sanitize the JSON by correcting known non-standard tokens before parsing.
Example fix
// before — non-standard literal
string json = "{\"enabled\": True, \"value\": None}";
// after — standard JSON literals
string json = "{\"enabled\": true, \"value\": null}"; Defensive patterns
Strategy: validation
Validate before calling
// Pre-check that JSON literals are lowercase true/false/null
using System.Text.RegularExpressions;
bool HasStandardLiterals(string json)
{
// Flag non-standard capitalized or unrecognized literals in value positions
return !Regex.IsMatch(json, @"(?<!\w)(?:True|False|Null|None|Undefined|NaN|Infinity)(?!\w)");
} Try / catch
try
{
var result = JSONParser.SimpleParse(jsonString);
}
catch (JSONParseException ex) when (ex.Message.Contains("Invalid token"))
{
Debug.LogError($"Invalid JSON literal: {ex.Message}. Ensure true/false/null are lowercase.");
} Prevention
- Use a standard JSON serializer that always emits lowercase true/false/null.
- When integrating data from Python/YAML sources, be aware of capitalized True/False/None.
- Validate JSON with a linter that checks for non-standard literals.
- Never substitute language-native boolean representations directly into JSON strings.
When it happens
Trigger: Parsing JSON where a value position contains an unquoted token starting with a letter that is not true, false, or null — e.g. {"flag": True} (capital T), {"x": undefined}, {"v": NaN}. The parser consumed four characters and none matched any known constant.
Common situations: JavaScript-style boolean/null literals (True, False, Null, None) used instead of JSON-standard lowercase forms, language-agnostic data sources emitting non-JSON literals, corrupted or partially-garbled JSON, copy-paste from Python or YAML where True/None are capitalized.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Invalid unicode escape char near {}
- Invalid escape char '{}' near {}
- End of json while parsing while parsing string near {}
- Cannot convert string to float : '{}' at {}
- Tried to read non-string json value as string
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/41b29963784c1013.
Report an issue: GitHub.