Stuck with an OSM file your web map can’t read? Here’s how to convert OSM data to GeoJSON: run osmtogeojson on the file, or export from Overpass turbo, and you get a ready FeatureCollection.
This guide belongs to the street map tools section, which covers other ways of working with map data.
| Item | Value |
|---|---|
| Global install command | npm install -g osmtogeojson |
| Accepted input | OSM data as an XML DOM or in OSM JSON |
| Memory needed | About 4-5 times the input data size |
| Large-file threshold | 100 MB and above, where extra memory is recommended |
| GDAL OSM driver | Reads OSM XML and PBF files, starting with GDAL 1.10 |
These figures come from the osmtogeojson README and the OGR page on the OpenStreetMap Wiki. They can change, so check the source before you rely on them.
Choose a converter that fits your OSM data
Your best route depends on where the data lives. The OpenStreetMap Wiki’s GeoJSON page lists several converters, and these are the ones that matter most:
- osmtogeojson: a specialised tool that converts OSM data to GeoJSON.
- Overpass turbo: an export function that copies a query result as GeoJSON to the clipboard or saves it to a file.
- ogr2ogr: a general tool for many geo data formats, including GeoJSON and OSM XML.
- osmium-tool: has an export function that transforms OSM data to GeoJSON.
- JOSM: saves to GeoJSON and can re-open the result.
- osm2geojson: a Python converter for OSM XML and Overpass XML or JSON.
- BBBike.org extract service: offers GeoJSON for an area of your choosing, updated weekly.
If you already hold a .osm file, start with osmtogeojson. If you only need one area or one feature type, the Overpass turbo export saves a step.
If paper is your goal rather than data, the guide on how to print a street map is a better fit.
Convert a file with osmtogeojson
The osmtogeojson README gives a short command-line routine:
- Install it globally with npm: npm install -g osmtogeojson.
- Run it on your file: osmtogeojson file.osm > file.geojson.
- List the supported options with osmtogeojson –help.
Very large files need care. The README recommends giving the process extra memory for data files of 100 MB and above, to avoid out-of-memory errors.
It also says osmtogeojson typically needs about 4-5 times the input data size. Plan your memory around that ratio before you start a long run.
On a Unix system, the README gives this command, where you should swap the memory value for whatever your machine can spare: node –max_old_space_size=8192 `which osmtogeojson` large.osm > large.geojson
Working in code instead? Install the library with npm install osmtogeojson, then call var osmtogeojson = require(‘osmtogeojson’); osmtogeojson(osm_data);. Per the README, the data can be an XML DOM or OSM JSON.
Three optional settings change how the output looks:
- flatProperties: when true, feature properties become a simple key-value list instead of a structured object with separate tags and metadata.
- uninterestingTags: either a blacklist of tag keys or a callback function.
- polygonFeatures: a json object or callback that decides whether a closed way becomes a Polygon or a LineString.
Export GeoJSON from Overpass turbo
If you query data rather than download files, the Overpass turbo GeoJSON page explains that Overpass turbo uses the osmtogeojson library under the hood. You get the same FeatureCollection structure either way.
Run your query, then use the export function to copy the result as GeoJSON or save it to a file. The wiki’s GeoJSON page describes both options.
Expect gaps, because the export is not a mirror of the raw data. The wiki says it leaves out some things Overpass API can return, such as Overpass areas, objects without coordinates and way-nodes, and arbitrary relations only appear through their children.
The example output on that page also carries a copyright field copied from the data source. Its sample text says the data is made available under ODbL, so keep that attribution with your file.
Convert with ogr2ogr and GDAL
The OGR page describes ogr2ogr as a utility that can read OSM data and write formats supported by OGR. Its OSM driver reads OSM XML and PBF files, starting with GDAL 1.10.
The wiki’s minimal example writes a shapefile: ogr2ogr -f “ESRI Shapefile” outputdir inputosm.osm
The same pattern takes any format OGR can write, so you can try ogr2ogr -f GeoJSON output.geojson input.osm and open the result to check it. That GeoJSON variant is an adaptation of the wiki’s pattern, not a line copied from it.
Tags are the part to watch. The wiki says OSM tags are kept as text in a single column named all_tags or other_tags, depending on osmconf.ini, so inspect a few features before you build on the output.
What the GeoJSON output contains
The README says each Feature has an id formed from the type and id of the original object, such as node/123, plus a properties member with the items below. You can read the details in the osmtogeojson README.
- type and id: the OSM data type and the OSM id.
- tags: a collection of all tags.
- meta: metadata such as version, timestamp and user.
- relations: an array of relations the feature belongs to.
- tainted: a flag set when the geometry is incomplete, for example missing nodes of a way.
The converter includes exactly one feature for each unconnected or tagged node, each way and each multipolygon. Simple multipolygons with a single closed outer way appear through that outer way.

Overpass turbo’s flavour differs slightly, as the wiki page shows. Metadata keys begin with an @ sign, and tags that already begin with @ are escaped with an extra @ in front.
How do you check and display the result?
Before you ship a file, test it. The GeoJSON wiki page points to a few helpful sites and libraries:
- geojsonlint.com checks the validity of GeoJSON data.
- geojson.io lets you author and share GeoJSON files on an OpenStreetMap base map.
- Leaflet, OpenLayers and Mapbox GL can each add GeoJSON to a map.
The same page warns, as of its September 2026 edit, that JOSM does not save projection information and will not warn you when you open GeoJSON with unusual projections. If a layer lands in the wrong place, suspect the projection first.
Once your file displays correctly, you may want live queries instead of static files, and the notes on a free map api cover that route.
Frequently asked questions
Can osmtogeojson read a PBF file?
Show answer
Its documented input is an XML DOM or OSM JSON, so a PBF file needs another step first. The GDAL OSM driver reads PBF, and osmium-tool offers an export function, both described on the OpenStreetMap Wiki’s GeoJSON page and OGR page.
Why are some objects missing from my GeoJSON?
Show answer
The Overpass turbo wiki states there is no one-to-one match between OSM data and the exported GeoJSON. Features with incomplete geometry also get flagged as tainted, as the wiki page and the README explain.
Do I keep the OSM tags after converting?
Show answer
With osmtogeojson, yes: every feature carries a tags collection, or flat key-value properties if you enable flatProperties. The README lists both layouts.
Can I reuse the converted data freely?
Show answer
Conversion does not remove the data’s licence. The sample export on the Overpass turbo wiki page names ODbL, so read those terms before you publish. This site is independent and not affiliated with the OpenStreetMap project, and nothing here is legal advice.



