OrchardCMS/OrchardCore · error · FormatException
Unsupported JSON token
Error message
Unsupported JSON token '{value.ValueKind}' was found. What it means
VisitValue handles Object, Array, Number, String, True, False and Null JSON value kinds; any other ValueKind reaching the default branch throws FormatException 'Unsupported JSON token ... was found.'. In practice this is a defensive invariant for JsonValueKind values not covered (e.g. Undefined from a default-constructed element).
Solutions
- Inspect the ValueKind reported in the message and ensure only well-formed JsonDocument/JsonElement values are traversed
- Upgrade or check OrchardCore/System.Text.Json version alignment if a new JsonValueKind appeared
- Avoid constructing JsonElement manually; always parse via JsonDocument.Parse
- Capture the full exception with a stack trace to identify which property produced the unsupported token
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure elements come from a parsed document using var doc = JsonDocument.Parse(document, JOptions.Document); // ValueKinds are then always one of the supported kinds
Try / catch
try { JsonConfigurationParser.Parse(document); }
catch (FormatException ex) when (ex.Message.StartsWith("Unsupported JSON token"))
{ log.LogError(ex, "Uninitialized/unsupported JsonElement encountered"); } Prevention
- Never pass default(JsonElement) or manually constructed elements
- Always traverse elements obtained from JsonDocument.Parse
- Keep System.Text.Json and OrchardCore versions in sync
- Include stack traces when reporting to locate the offending property
When it happens
Trigger: Extremely rare with normal System.Text.Json parsing; occurs if a default(JsonElement) or otherwise uninitialized element (ValueKind Undefined/Uninitialized) is passed into the visitor, typically through reflection, custom subclassing, or a bug in calling code constructing elements manually.
Common situations: Custom code paths or tests that hand-construct JsonElement values; a framework/version change introducing a new ValueKind not yet handled by this parser; debugging tools feeding synthetic elements.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- A duplicate key ' ' was found.
- Can't use the non numeric key
- Can't use the numeric key
- is missing the required "orchardBaseUrl" field.
- Could not parse the JSON document.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/bdab7149303adb6c.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Abstractions/Shell/Configuration/Internal/JsonConfigurationParser.cs:166
case JsonValueKind.Null:
// Skipping null values is useful to override array items,
// it allows to keep non null items at the right position.
if (visitArray && value.ValueKind == JsonValueKind.Null)
{
break;
}
var key = _paths.Peek();
if (_data.ContainsKey(key))
{
throw new FormatException($"A duplicate key '{key}' was found.");
}
_data[key] = value.ToString();
break;
default:
throw new FormatException($"Unsupported JSON token '{value.ValueKind}' was found.");
}
}
private void EnterContext(string context) =>
_paths.Push(_paths.Count > 0 ?
_paths.Peek() + ConfigurationPath.KeyDelimiter + context :
context);
private void ExitContext() => _paths.Pop();
}
View on GitHub (pinned to 4306c0717f)