{"record":{"id":"73f0080e57c55bd1","repo":"dgraph-io/dgraph","slug":"unexpected-type-for-val-for-attr-s-while-convert","errorCode":null,"errorMessage":"unexpected type for val for attr: %s while converting to nquad","messagePattern":"unexpected type for val for attr: (.+?) while converting to nquad","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/json_parser.go","lineNumber":259,"sourceCode":"\t\t// password value (types.PasswordID) - Issue#2623\n\t\tnq.ObjectValue = &api.Value{Val: &api.Value_StrVal{StrVal: v}}\n\n\tcase float64:\n\t\tif v == 0 && op == DeleteNquads {\n\t\t\tnq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}}\n\t\t\treturn nil\n\t\t}\n\t\tnq.ObjectValue = &api.Value{Val: &api.Value_DoubleVal{DoubleVal: v}}\n\n\tcase bool:\n\t\tif !v && op == DeleteNquads {\n\t\t\tnq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}}\n\t\t\treturn nil\n\t\t}\n\t\tnq.ObjectValue = &api.Value{Val: &api.Value_BoolVal{BoolVal: v}}\n\n\tdefault:\n\t\treturn fmt.Errorf(\"unexpected type for val for attr: %s while converting to nquad\", k)\n\t}\n\treturn nil\n\n}\n\nfunc (buf *NQuadBuffer) checkForDeletion(mr mapResponse, m map[string]interface{}, op int) {\n\t// Since uid is the only key, this must be S * * deletion.\n\tif op == DeleteNquads && len(mr.uid) > 0 && len(m) == 1 && len(mr.rawFacets) == 0 {\n\t\tbuf.Push(&api.NQuad{\n\t\t\tSubject:     mr.uid,\n\t\t\tPredicate:   x.Star,\n\t\t\tNamespace:   mr.namespace,\n\t\t\tObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}},\n\t\t})\n\t}\n}\n\nfunc handleGeoType(val map[string]interface{}, nq *api.NQuad) (bool, error) {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/json_parser.go#L241-L277","documentation":"During JSON-to-NQuad conversion, handleBasicType in chunker/json_parser.go:259 handles scalar attribute values (bool, string, numeric, star). When a value's Go type matches none of the supported switch cases, the parser cannot represent it as an NQuad object value and returns this error naming the predicate. It means the JSON document contained a scalar type the RDF mapper does not support for an attribute.","triggerScenarios":"Calling NQuadBuffer.ParseJSON or FastParseJSON with a JSON map whose attribute value is a basic Go type outside the handled set (e.g. a raw nil, or a JSON number decoded into an unexpected numeric shape) so the type switch in handleBasicType falls to the default branch.","commonSituations":"Feeding documents produced by another serializer that emits unusual scalars (e.g. nulls or high-precision numbers), or a schema change where a predicate that used to hold a string now receives an unsupported scalar.","solutions":["Log/inspect the offending attribute's value type in the JSON document and coerce it to a supported scalar (string, bool, number) before parsing.","Replace unsupported values like null with an explicit value or drop the predicate from the document.","If it must be preserved, wrap the value in a structure the parser supports (map for nested object, array for list) instead of a bare scalar."],"exampleFix":"// before\n{\"age\": null}\n// after\n{\"age\": \"0\"}","handlingStrategy":"validation","validationCode":"func isSupportedScalar(v interface{}) bool {\n\tswitch v.(type) {\n\tcase string, bool, int, int64, float64, json.Number:\n\t\treturn v != nil\n\t}\n\treturn false\n}\n// reject any key whose value is not isSupportedScalar before parsing","typeGuard":"func supportedScalar(v interface{}) (interface{}, bool) {\n\tif v == nil {\n\t\treturn nil, false\n\t}\n\tswitch v.(type) {\n\tcase string, bool, float64, int64, json.Number:\n\t\treturn v, true\n\t}\n\treturn nil, false\n}","tryCatchPattern":"if err := buf.ParseJSON(b, op); err != nil && strings.Contains(err.Error(), \"unexpected type for val for attr\") {\n\t// sanitize the document (replace nulls/odd scalars) and retry once\n}","preventionTips":["Never emit JSON null for predicates in import documents","Normalize all scalars to strings, numbers, or booleans before import","Run a pre-pass validator over documents in CI"],"tags":["json-parser","type-conversion","nquad","dgraph"],"backgroundTag":"unsupported-value-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}