dgraph-io/dgraph · error

couldn't convert value: %s to geo type

Error message

couldn't convert value: %s to geo type

What it means

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).

Source

Thrown at chunker/json_parser.go:305

			return true, err
		}
		if ok {
			return true, nil
		}
	}
	return false, nil
}

func tryParseAsGeo(b []byte, nq *api.NQuad) (bool, error) {
	var g geom.T
	err := geojson.Unmarshal(b, &g)
	if err != nil {
		return false, nil
	}

	geo, err := types.ObjectValue(types.GeoID, g)
	if err != nil {
		return false, fmt.Errorf("couldn't convert value: %s to geo type", string(b))
	}

	nq.ObjectValue = geo
	return true, nil
}

// NQuadBuffer batches up batchSize NQuads per push to channel, accessible via Ch(). If batchSize is
// negative, it only does one push to Ch() during Flush.
type NQuadBuffer struct {
	batchSize int
	nquads    []*api.NQuad
	nqCh      chan []*api.NQuad
	predHints map[string]pb.Metadata_HintType
}

// NewNQuadBuffer returns a new NQuadBuffer instance with the specified batch size.
func NewNQuadBuffer(batchSize int) *NQuadBuffer {
	buf := &NQuadBuffer{

View on GitHub (pinned to 759e242be6)

Solutions

  1. Validate the GeoJSON: "type" must be one of Point/MultiPoint/Polygon/MultiPolygon/LineString/MultiLineString and "coordinates" must have the matching structure.
  2. Fix coordinate arity, e.g. Point requires [lon, lat] as two numbers, not a nested array or single number.
  3. Re-export the geometry from the source system as standard GeoJSON before importing.

Example fix

// before
{"type": "Point", "coordinates": [[1.0, 2.0]]}
// after
{"type": "Point", "coordinates": [1.0, 2.0]}
Defensive patterns

Strategy: validation

Validate before calling

var validGeoTypes = map[string]bool{"Point": true, "MultiPoint": true, "LineString": true, "MultiLineString": true, "Polygon": true, "MultiPolygon": true}
func validGeo(val map[string]interface{}) bool {
	t, _ := val["type"].(string)
	return validGeoTypes[t]
}

Type guard

func isGeoJSON(v interface{}) bool {
	m, ok := v.(map[string]interface{})
	if !ok || len(m) != 2 {
		return false
	}
	t, ok := m["type"].(string)
	if !ok {
		return false
	}
	coords, ok := m["coordinates"].([]interface{})
	return validGeoTypes[t] && ok && len(coords) > 0
}

Try / catch

if err := buf.ParseJSON(b, op); err != nil && strings.Contains(err.Error(), "to geo type") {
	// extract the raw value from the error message and repair its GeoJSON structure
}

Prevention

When it happens

Trigger: 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]).

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/51750d4fd7c1663e. Report an issue: GitHub.