{"record":{"id":"15e1ad3058cbb058","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-json-value-jsonvalue","errorCode":null,"errorMessage":"Invalid JSON value: ${jsonValue}","messagePattern":"Invalid JSON value: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorMode/ModeService.cs","lineNumber":922,"sourceCode":"                    var clonedList = new List<object>(listValue.Count);\n                    foreach (var item in listValue)\n                        clonedList.Add(DeepClone(item));\n                    return clonedList;\n                }\n\n                var dictionaryValue = jsonValue as JSONObject;\n                if (dictionaryValue != null)\n                {\n                    var clonedDict = new Dictionary<string, object>(dictionaryValue.Count);\n                    foreach (DictionaryEntry kvp in dictionaryValue)\n                        clonedDict.Add((string)kvp.Key, DeepClone(kvp.Value));\n                    return clonedDict;\n                }\n\n                if (jsonValue is bool || jsonValue is double || jsonValue is string)\n                    return jsonValue;\n\n                throw new ArgumentException(\"Invalid JSON value: \" + jsonValue);\n            }\n        }\n    }\n}\n","sourceCodeStart":904,"sourceCodeEnd":927,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorMode/ModeService.cs#L904-L927","documentation":"Thrown by ModeService.DeepClone for any JSON value type it does not explicitly clone. The method only handles JSONObject (mapped to Dictionary<string,object>), bool, double, and string; any other runtime type — including null, JSON arrays (typically List<object>), nested numbers of other types, or custom objects — falls through to the ArgumentException.","triggerScenarios":"DeepClone receives a value that is null (none of the is-checks match), an array/List (not a JSONObject), a long/float boxed as something other than double, or an arbitrary object placed into the mode descriptor JSON tree.","commonSituations":"A mode descriptor JSON contains arrays or null values that the clone routine cannot represent; a JsonUtility/JSON parser that materializes integers as long instead of double; mode service extensions feeding hand-built dictionaries with unsupported leaf types.","solutions":["Ensure all JSON leaf values are bool, double, or string; convert integer leaves to double or string before insertion.","Wrap arrays inside a JSONObject (object with keyed entries) or extend the clone routine if you control it.","Validate the JSON tree shape before passing it to the mode service: reject null leaves and non-conformant types.","Catch ArgumentException around mode-service calls and surface a clearer mode-descriptor error."],"exampleFix":"// before\ndict[\"counts\"] = new List<object>{ 1, 2, 3 }; // array leaf -> throws\n\n// after\ndict[\"count\"] = (double)1; // supported scalar leaf","handlingStrategy":"try-catch","validationCode":"static bool IsCloneableJsonValue(object v) => v is bool || v is double || v is string || v is JSONObject || v == null ? (v != null ? true : false) : false; // reject null and unsupported","typeGuard":"static bool IsValidJsonLeaf(object v) => v is bool || v is double || v is string;","tryCatchPattern":"try { var clone = ModeService.DeepClone(value); } catch (ArgumentException ex) { Debug.LogError($\"Unsupported JSON value: {ex.Message}\"); }","preventionTips":["Keep JSON leaf values as bool, double, or string only.","Convert integer leaves to double before inserting into the descriptor tree.","Avoid null leaves and bare arrays; wrap structured data in JSONObject."],"tags":["csharp","unity-editor","json","mode-service","serialization"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}