{"record":{"id":"90c50377d257110b","repo":"elsa-workflows/elsa-core","slug":"unsupported-jsonvaluekind-element-valuekind","errorCode":null,"errorMessage":"Unsupported JsonValueKind: {element.ValueKind}","messagePattern":"Unsupported JsonValueKind: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Expressions.JavaScript/ObjectConverters/JsonElementConverter.cs","lineNumber":39,"sourceCode":"        return false;\n    }\n\n    private static JsValue ConvertJsonElementToJsValue(Engine engine, JsonElement element) =>\n        element.ValueKind switch\n        {\n            JsonValueKind.Object => JsValue.FromObject(engine, JsonObject.Create(element)),\n            JsonValueKind.Array => JsValue.FromObject(engine, JsonArray.Create(element)),\n            // JsString.Create is the counterpart of the JsNumber.Create and JsBoolean uses below: it produces the\n            // string value directly, where JsValue.FromObject would re-enter the whole conversion pipeline — the\n            // registered object converters, this one included, followed by the default converter's type switch —\n            // to arrive at the same call. It became public in Jint 4.15.3.\n            JsonValueKind.String => JsString.Create(element.GetString()!),\n            JsonValueKind.Number => element.TryGetInt32(out var intValue) ? JsNumber.Create(intValue) : JsNumber.Create(element.GetDouble()),\n            JsonValueKind.True => JsBoolean.True,\n            JsonValueKind.False => JsBoolean.False,\n            JsonValueKind.Undefined => JsValue.Undefined,\n            JsonValueKind.Null => JsValue.Null,\n            _ => throw new InvalidOperationException($\"Unsupported JsonValueKind: {element.ValueKind}\")\n        };\n}","sourceCodeStart":21,"sourceCodeEnd":41,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Expressions.JavaScript/ObjectConverters/JsonElementConverter.cs#L21-L41","documentation":"JsonElementConverter maps a System.Text.Json JsonElement to a Jint JsValue, handling Object, Array, String, Number, True, False, Undefined, and Null kinds. Any other JsonValueKind (e.g. certain document-root or exotic kinds surfaced by newer parsers) has no mapping and throws this InvalidOperationException. It marks an unhandled JSON element shape in the JavaScript expression bridge.","triggerScenarios":"Passing a JsonElement whose ValueKind is not one of the handled kinds into TryConvert during JS variable/argument conversion — typically a JsonDocument root element obtained without Read(), or a kind introduced by a newer System.Text.Json version.","commonSituations":"Passing JsonDocument.RootElement before calling the clone/read pattern; converting values from custom JSON readers; framework upgrades introducing kinds the converter predates; feeding non-standard JSON tokens.","solutions":["Ensure the JsonElement is fully materialized (use JsonDocument.Parse(...).RootElement or Clone()) before conversion","Check element.ValueKind before calling and normalize unsupported kinds to Object/Null","Inspect the value's ValueKind at the failing point and fix the producer of the JSON","Extend JsonElementConverter.ConvertJsonElementToJsValue with a mapping for the missing kind"],"exampleFix":"// before\nJsValue v = converter.Convert(jsonDoc.RootElement); // kind not handled\n// after\nusing var doc = JsonDocument.Parse(json);\nvar element = doc.RootElement.Clone(); // materialized Object/Array/String/Number\nJsValue v = converter.Convert(element);","handlingStrategy":"type-guard","validationCode":"bool IsSupportedKind(JsonElement e) => e.ValueKind is JsonValueKind.Object or JsonValueKind.Array\n    or JsonValueKind.String or JsonValueKind.Number\n    or JsonValueKind.True or JsonValueKind.False\n    or JsonValueKind.Undefined or JsonValueKind.Null;\nif (!IsSupportedKind(element)) throw new InvalidOperationException($\"Unsupported JsonValueKind: {element.ValueKind}\");","typeGuard":"static bool IsConvertibleToJsonValue(JsonElement element) =>\n    element.ValueKind is not (JsonValueKind.Object or JsonValueKind.Array or JsonValueKind.String\n        or JsonValueKind.Number or JsonValueKind.True or JsonValueKind.False\n        or JsonValueKind.Undefined or JsonValueKind.Null) is false;","tryCatchPattern":"try { jsValue = converter.ConvertJsonElementToJsValue(element); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Unsupported JsonValueKind\"))\n{\n    // normalize: treat unhandled kinds as Null or re-materialize the element\n    jsValue = JsValue.Null;\n}","preventionTips":["Always pass fully materialized JsonElements (RootElement from a parsed JsonDocument, or Clone())","Check ValueKind before crossing the JSON-to-JS boundary","Keep System.Text.Json and Jint converter code in sync with new JsonValueKind values","Unit-test the converter against every JsonValueKind"],"tags":["json","javascript","jint","converter"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}