{"record":{"id":"99240b5b0e8d89ea","repo":"JamesNK/Newtonsoft.Json","slug":"could-not-determine-json-object-type-for-type-0-99240b","errorCode":null,"errorMessage":"Could not determine JSON object type for type {0}.","messagePattern":"Could not determine JSON object type for type (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JValue.cs","lineNumber":677,"sourceCode":"            }\n            else if (value is bool)\n            {\n                return JTokenType.Boolean;\n            }\n            else if (value is Guid)\n            {\n                return JTokenType.Guid;\n            }\n            else if (value is Uri)\n            {\n                return JTokenType.Uri;\n            }\n            else if (value is TimeSpan)\n            {\n                return JTokenType.TimeSpan;\n            }\n\n            throw new ArgumentException(\"Could not determine JSON object type for type {0}.\".FormatWith(CultureInfo.InvariantCulture, value.GetType()));\n        }\n\n        private static JTokenType GetStringValueType(JTokenType? current)\n        {\n            if (current == null)\n            {\n                return JTokenType.String;\n            }\n\n            switch (current.GetValueOrDefault())\n            {\n                case JTokenType.Comment:\n                case JTokenType.String:\n                case JTokenType.Raw:\n                    return current.GetValueOrDefault();\n                default:\n                    return JTokenType.String;\n            }","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JValue.cs#L659-L695","documentation":"Thrown by the internal JValue.GetValueType helper when a .NET object is assigned into a JValue but its runtime type is not one of the supported primitive/category types (string, integer kinds, Enum, BigInteger, float/double/decimal, DateTime/DateTimeOffset, byte[], bool, Guid, Uri, TimeSpan). The {0} placeholder is value.GetType(). This indicates an attempt to wrap an unsupported CLR type as a scalar JValue, which only models JSON primitives.","triggerScenarios":"Constructing new JValue(customObject) where customObject is an arbitrary class/struct/record that is not a primitive or one of the known value types, e.g. new JValue(new MyPoco()). Also triggered by reflection-driven code that forwards an unrecognised runtime type into a JValue constructor or WriteTo path that calls GetValueType.","commonSituations":"Trying to store a complex object directly as a JValue instead of serializing it to a JObject; bugs in custom JsonConverter implementations that build JValues from arbitrary input; assigning anonymous types.","solutions":["Serialize the object to a JToken first: JToken.FromObject(myPoco) yields a JObject/JArray, not a JValue.","If you meant to store a string form, call myObject.ToString() (or JsonConvert) and wrap that string in a JValue.","Add a custom JsonConverter that converts the unsupported type to a supported primitive before constructing the JValue."],"exampleFix":"// before\nvar v = new JValue(new MyPoco());\n\n// after\nvar token = JToken.FromObject(new MyPoco());","handlingStrategy":"validation","validationCode":"var t = value.GetType();\nif (!IsSupportedJValueType(t)) { token = JToken.FromObject(value); } else { token = new JValue(value); }","typeGuard":"static bool IsSupportedJValueType(Type t) => t.IsPrimitive || t.IsEnum || t == typeof(string) || t == typeof(decimal) || t == typeof(Guid) || t == typeof(Uri) || t == typeof(TimeSpan) || t == typeof(DateTime) || t == typeof(DateTimeOffset) || t == typeof(byte[]) || t == typeof(System.Numerics.BigInteger);","tryCatchPattern":"try { return new JValue(value); } catch (ArgumentException) { return JToken.FromObject(value); }","preventionTips":["Use JToken.FromObject for complex types instead of new JValue.","Add a JsonConverter for unsupported custom types.","Unit-test JValue construction with representative input types."],"tags":["jvalue","unsupported-type","argumentexception","linq-to-json","converter"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}