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

  1. Check the JSON at the reported position for non-standard literal values (True instead of true, None instead of null, etc.).
  2. Ensure the data producer serializes using a standard JSON library rather than manual string building.
  3. If the source is under your control, replace capitalized or non-standard literals with lowercase JSON equivalents.
  4. 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

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

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/41b29963784c1013. Report an issue: GitHub.