{"record":{"id":"51750d4fd7c1663e","repo":"dgraph-io/dgraph","slug":"couldn-t-convert-value-s-to-geo-type","errorCode":null,"errorMessage":"couldn't convert value: %s to geo type","messagePattern":"couldn't convert value: (.+?) to geo type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/json_parser.go","lineNumber":305,"sourceCode":"\t\t\treturn true, err\n\t\t}\n\t\tif ok {\n\t\t\treturn true, nil\n\t\t}\n\t}\n\treturn false, nil\n}\n\nfunc tryParseAsGeo(b []byte, nq *api.NQuad) (bool, error) {\n\tvar g geom.T\n\terr := geojson.Unmarshal(b, &g)\n\tif err != nil {\n\t\treturn false, nil\n\t}\n\n\tgeo, err := types.ObjectValue(types.GeoID, g)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"couldn't convert value: %s to geo type\", string(b))\n\t}\n\n\tnq.ObjectValue = geo\n\treturn true, nil\n}\n\n// NQuadBuffer batches up batchSize NQuads per push to channel, accessible via Ch(). If batchSize is\n// negative, it only does one push to Ch() during Flush.\ntype NQuadBuffer struct {\n\tbatchSize int\n\tnquads    []*api.NQuad\n\tnqCh      chan []*api.NQuad\n\tpredHints map[string]pb.Metadata_HintType\n}\n\n// NewNQuadBuffer returns a new NQuadBuffer instance with the specified batch size.\nfunc NewNQuadBuffer(batchSize int) *NQuadBuffer {\n\tbuf := &NQuadBuffer{","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/json_parser.go#L287-L323","documentation":"tryParseAsGeo (chunker/json_parser.go:305) unmarshals the candidate JSON into a geo object and converts it via types.ObjectValue(types.GeoID, ...). If that conversion fails, the value looked like geo but is not a valid geo type, and this error is returned with the raw JSON. It indicates a malformed geo shape (bad type string or invalid coordinates).","triggerScenarios":"An attribute value shaped as {\"type\":...,\"coordinates\":...} where the type is not a recognized geo type or the coordinates array is malformed (wrong arity, e.g. a Point with a scalar instead of [lon,lat]).","commonSituations":"Hand-written geo JSON with typos (\"point\" vs \"Point\" handled upstream, but wrong coordinate nesting like [[1,2]] for a Point), or data exported from another system using GeoJSON variants Dgraph rejects.","solutions":["Validate the GeoJSON: \"type\" must be one of Point/MultiPoint/Polygon/MultiPolygon/LineString/MultiLineString and \"coordinates\" must have the matching structure.","Fix coordinate arity, e.g. Point requires [lon, lat] as two numbers, not a nested array or single number.","Re-export the geometry from the source system as standard GeoJSON before importing."],"exampleFix":"// before\n{\"type\": \"Point\", \"coordinates\": [[1.0, 2.0]]}\n// after\n{\"type\": \"Point\", \"coordinates\": [1.0, 2.0]}","handlingStrategy":"validation","validationCode":"var validGeoTypes = map[string]bool{\"Point\": true, \"MultiPoint\": true, \"LineString\": true, \"MultiLineString\": true, \"Polygon\": true, \"MultiPolygon\": true}\nfunc validGeo(val map[string]interface{}) bool {\n\tt, _ := val[\"type\"].(string)\n\treturn validGeoTypes[t]\n}","typeGuard":"func isGeoJSON(v interface{}) bool {\n\tm, ok := v.(map[string]interface{})\n\tif !ok || len(m) != 2 {\n\t\treturn false\n\t}\n\tt, ok := m[\"type\"].(string)\n\tif !ok {\n\t\treturn false\n\t}\n\tcoords, ok := m[\"coordinates\"].([]interface{})\n\treturn validGeoTypes[t] && ok && len(coords) > 0\n}","tryCatchPattern":"if err := buf.ParseJSON(b, op); err != nil && strings.Contains(err.Error(), \"to geo type\") {\n\t// extract the raw value from the error message and repair its GeoJSON structure\n}","preventionTips":["Validate GeoJSON with a library before import","Enforce correct coordinate arity per geometry type (Point: [lon,lat])","Standardize on canonical GeoJSON exports from source systems"],"tags":["json-parser","geo","geojson","dgraph"],"backgroundTag":"invalid-geojson","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}