{"record":{"id":"4660bd5f24c20692","repo":"Leaflet/Leaflet","slug":"invalid-geojson-object","errorCode":null,"errorMessage":"Invalid GeoJSON object.","messagePattern":"Invalid GeoJSON object\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/layer/GeoJSON.js","lineNumber":230,"sourceCode":"\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t// @function coordsToLatLng(coords: Array): LatLng\n\t// Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t// or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t// @function coordsToLatLngs(coords: Array, levelsDeep?: Number, coordsToLatLng?: Function): Array\n\t// Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/Leaflet/Leaflet/blob/c96f31a7a350a07cfbc852cf88e6ca69af5f5ec9/src/layer/GeoJSON.js#L212-L248","documentation":"Thrown by GeoJSON.geometryToLayer() in the default branch of its switch on geometry.type. Recognized types are Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, GeometryCollection, FeatureCollection. Any other (or misspelled) type falls through and throws. Note: a geometry with no coordinates returns null earlier (line 179) and does not throw.","triggerScenarios":"GeoJSON.geometryToLayer({type:'Feature', geometry:{type:'Poin', coordinates:[0,0]}}) (typo); a custom geometry type not in the RFC 7946 list; geometry.type undefined reaching the switch (when coordinates are present but type is missing).","commonSituations":"Third-party GeoJSON with a non-standard geometry type; hand-built features with a typo; truncated JSON where 'type' was dropped; mixing older GeoJSON variants.","solutions":["Validate geometry.type against the allowed set before calling geometryToLayer.","Use a JSON-Schema validator (e.g. @turf helpers or geojson-validation) on incoming features.","Normalize/correct known typos (e.g. 'Poin' -> 'Point') upstream.","Skip features whose type is unrecognized rather than letting them reach the switch."],"exampleFix":"// before\nL.geoJSON(rawFeature); // rawFeature.geometry.type === 'Poin' -> throws\n// after\nconst ALLOWED = new Set(['Point','MultiPoint','LineString','MultiLineString','Polygon','MultiPolygon','GeometryCollection','FeatureCollection']);\nif (ALLOWED.has(rawFeature.geometry?.type)) {\n  L.geoJSON(rawFeature);\n} else { console.warn('Unsupported geometry', rawFeature); }","handlingStrategy":"validation","validationCode":"const GEOJSON_TYPES = new Set(['Point','MultiPoint','LineString','MultiLineString','Polygon','MultiPolygon','GeometryCollection','FeatureCollection','Feature']);\nfunction isKnownGeometry(g) {\n  return g && GEOJSON_TYPES.has(g.type) && (g.type === 'GeometryCollection' ? Array.isArray(g.geometries) : (g.coordinates !== undefined || g.geometry !== undefined || g.features !== undefined));\n}\nif (isKnownGeometry(feature)) L.geoJSON(feature);","typeGuard":"function isValidGeoJSONFeature(v) {\n  if (!v || typeof v !== 'object') return false;\n  const t = v.type;\n  return ['Feature','Point','MultiPoint','LineString','MultiLineString','Polygon','MultiPolygon','GeometryCollection','FeatureCollection'].includes(t);\n}","tryCatchPattern":"try { return GeoJSON.geometryToLayer(feature, options); }\ncatch (e) { if (/Invalid GeoJSON object/.test(e.message)) { console.warn('Skipping unsupported geometry', feature); return null; } throw e; }","preventionTips":["Validate incoming GeoJSON against RFC 7946 (geojson-validation, @turf/invariant) before passing to L.geoJSON.","Normalize data from third-party sources to correct known type typos.","Skip unrecognized geometry types rather than relying on the default branch to throw."],"tags":["geojson","parsing","input-validation","geometry-type"],"backgroundTag":null,"analyzedSha":"c96f31a7a350a07cfbc852cf88e6ca69af5f5ec9","analyzedAt":"2026-08-13T03:13:23.068Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}