Home / GIS and Open Map Data for Beginners

GeoJSON to KML: Convert Without Losing Your Data (and What Never Survives)

Colorful code on a monitor, the kind of text file a GeoJSON document is

Photo: Nemuel Sereti / Pexels

GeoJSON is the format web mapping runs on. KML is the format Google Earth runs on. Sooner or later every GIS workflow needs to move data from the first world into the second: a dataset built in code that a client wants to open in Earth, a set of field boundaries headed for a presentation globe. The conversion itself is one command. The craft is knowing what the command quietly drops. This guide converts carefully, with the losses named in advance and the workarounds attached. (Going the other common direction? Our GeoJSON to shapefile guide owns that conversion; this one is KML only.)

Interactive tool

Convert GeoJSON to KML Without Losing Data

Check off each step as you finish it. Your progress stays on this page.

0 of 6 complete

0% done

What Each Format Carries

The mismatch starts with what the two formats think a feature is. A GeoJSON feature is a geometry plus an open bag of properties: any keys you like, holding strings, numbers, nested data. A KML placemark is a presentation object: a name, a description (which can hold HTML for the click balloon), a style, and a geometry, with attributes beyond name and description relegated to a side structure called ExtendedData. GeoJSON is data-first with almost no styling standard; KML is presentation-first with a real styling system and a grudging attitude to raw attributes. Every conversion quirk in this article flows from that difference in personality.

The good news, and it is genuinely good: both formats are longitude first, and both are defined on WGS 84. GeoJSON's specification (RFC 7946) fixed its coordinate reference system as WGS 84 longitude, latitude. KML likewise only speaks WGS 84. So the geometry itself converts without reprojection and without the axis-order trap that haunts other format pairs. If your coordinates land in the ocean after this conversion, something else went wrong; the formats agree on the map.

What Survives, What Needs Help, What Dies

GeoJSON elementFate in KMLHow to protect it
Geometry (Point, LineString, Polygon, Multi)Survives cleanlyNothing needed
Third position value (altitude)Survives as KML altitudeCheck altitude mode on display
name propertyBecomes the placemark name, if the converter maps itName the property exactly name
description propertyBecomes the balloon descriptionName it exactly description; HTML allowed
Any other propertyDropped by simple converters; kept as ExtendedData by good onesUse ogr2ogr or QGIS, and verify
Styling (colors, widths, icons)Mostly lostRestyle in Google Earth or KML after conversion
Nested or array property valuesFlattened or droppedFlatten to strings before converting
A developer's screen showing map data and code side by side
A developer's screen showing map data and code side by side

Method 1: ogr2ogr, the Reference Conversion

GDAL's command-line converter is the standard tool, and it handles the ExtendedData problem correctly:

```

ogr2ogr -f KML output.kml input.geojson

```

That is the whole command for a basic conversion. ogr2ogr writes each GeoJSON feature as a placemark, maps name and description when present, and carries the remaining properties into ExtendedData, where Google Earth shows them in the balloon as a table. Two refinements worth knowing: add -nln "Layer name" to control the KML folder name, and if your GeoJSON properties include a field you want as the placemark name but it is not called name, rename it in the source first rather than fighting the converter. After converting, open the KML in a text editor (it is plain XML, as our guide to getting coordinates from a KML file shows) and confirm the ExtendedData blocks contain your properties. Verifying takes one minute and is the difference between a conversion and a hope.

Method 2: QGIS, the Visual Conversion

Load the GeoJSON into QGIS (drag and drop works), right-click the layer, Export, Save Features As, and choose Keyhole Markup Language (KML) as the format. QGIS uses GDAL underneath, so the data handling matches Method 1, and the dialog lets you set the name and description fields explicitly from your attribute columns, which is the friendliest way to handle a dataset whose name field is called something else. The visual route has one advantage the command line lacks: you see the data on a map before and after, so a geometry problem is obvious rather than discovered by your client inside Google Earth.

Method 3: Online Converters, With a Privacy Warning

Browser-based converters handle small files adequately and are fine for public data. Two cautions. First, quality varies: the simplest ones drop every property except geometry, silently, which is the exact failure this article exists to prevent. Test with one feature whose properties you know and inspect the output. Second, privacy: uploading a file to a converter sends your data to someone's server. Field locations, client boundaries, and anything sensitive should never travel that road; ogr2ogr and QGIS run entirely on your machine. The rule is simple: online for trivia, local tools for data.

Styling: Accept the Loss, Then Restyle

GeoJSON has no official styling (the simplestyle convention used by some tools is just that, a convention), and KML styles do not map from it in any case. Colors even disagree about spelling: web colors are written red-green-blue, while KML color values are written alpha-blue-green-red, so a converter that tried would still have to translate. Plan on it: the KML that comes out of conversion wears default styling, and you apply presentation afterward, either by editing styles in Google Earth and re-saving, or by writing KML styles into the file if the deliverable justifies it. For a dataset headed to Earth for a client presentation, budget the restyling time into the job; it is not an error in your conversion, it is the formats being themselves.

KMZ: The Zipped Deliverable

If the KML is large, or it travels with icons and images, deliver a KMZ: a zipped KML (named doc.kml inside the archive) plus its attachments. Google Earth opens KMZ natively, file sizes shrink dramatically, and the bundle cannot lose its sidecar files in transit. Create one by zipping, or export directly to KMZ from Google Earth after styling. One warning from experience: a KMZ is opaque to quick inspection, so keep the plain KML as your working master and treat the KMZ as the shipping container, regenerated whenever the data changes.

A Worked Conversion, Inspected

Take one realistic feature: a GeoJSON point for a trailhead, with properties for name, description, surface type, and spaces. Run it through ogr2ogr. In the KML, the placemark's name is the trailhead's name, the balloon opens with the description, and down in an ExtendedData block sit surface and spaces, preserved as data items that Earth renders as a neat table in the balloon. Nothing was lost, because the converter did the ExtendedData work. Run the same feature through a bargain online converter and the output placemark has the point, the name if you are lucky, and silence where the other properties were. Same input, same format name on the output file, completely different information content. This is why the verification step in Method 1 is not pedantry. KML files do not announce what they dropped. Open the output, search for one property value you know should be there, and let the file prove itself before it travels.

Troubleshooting: Empty Balloons, Missing Features, Wrong Places

  • The balloon is empty or the name is missing. Your source properties were not called name and description, or the converter ignored them. Rename the fields in the GeoJSON (or set them explicitly in QGIS's export dialog) and convert again.
  • Features vanished. Mixed geometry types in one GeoJSON are the usual cause: some converters take the first type and skip the rest. Split the file by geometry type (points, lines, polygons) and convert each part, or use QGIS, which separates them into layers for you.
  • Everything landed in the wrong place. Not an axis problem this time, since both formats are longitude first. The real causes are a source file that was never WGS 84 (a local grid saved as GeoJSON by mistake) or coordinates written latitude first by whatever produced the file. Check one known point's raw numbers in the source; the truth is in the text.
  • The file will not open in Earth at all. Invalid XML, usually from an ampersand or angle bracket inside a description that a weak converter failed to escape. Converting with GDAL or QGIS, which escape properly, fixes it; so does keeping HTML in descriptions simple.

When Not to Convert at All

KML earns its conversion when the destination is Google Earth or an Earth-centric audience: clients, classrooms, field teams with Earth on their machines. If the destination is a web map, an app, or another developer, keep the GeoJSON. It is smaller, it parses natively in every web stack, and it keeps your properties as first-class data instead of ExtendedData passengers. Format conversions should always be the last step before a specific audience, never a storage decision: keep your master data in the richest format you work in (GeoJSON or a GeoPackage), and generate KML as a deliverable. Data converted early and stored converted is data quietly losing properties in a drawer.

Altitude and 3D Data in the Crossing

GeoJSON positions can carry a third value, altitude, and KML is a genuinely 3D format, so the crossing deserves a sentence of care. The altitude survives conversion as the third element of the KML coordinate tuple, in meters. What does not automatically survive is the interpretation: KML displays altitude according to the placemark's altitudeMode, and a converted file that defaults to clamping will drape your carefully measured heights onto the ground in Earth, looking for all the world like the altitude was dropped. It was not dropped; it is being ignored by the display mode. If your data is 3D (drone paths, flight tracks, utility lines with heights), check the altitude mode after conversion and set it to absolute where sea-level heights are meant. Verify with one feature whose height you know, the same one-point discipline as everywhere else in this guide.

Related Guides

This guide does not stand alone. The GIS and open map data guides below take up the questions it leads into:

Frequently Asked Questions

Does converting GeoJSON to KML lose my attribute data?

It can. Name and description map to the placemark's name and balloon text. Every other property survives only if the converter writes it to KML ExtendedData, which ogr2ogr and QGIS do and many simple online converters do not. Verify by opening the output and checking.

Do I need to reproject before converting GeoJSON to KML?

No. Both formats are defined on WGS 84 with longitude-first coordinates, so geometry converts directly. If your data is not actually in WGS 84 despite being in a GeoJSON file, fix that first; the conversion will faithfully preserve a wrong assumption.

Why did my colors and styles disappear?

GeoJSON carries no standard styling and KML's style system has no automatic mapping from GeoJSON properties, including a different color channel order. Restyle after conversion in Google Earth or by adding KML styles.

What is the ogr2ogr command for GeoJSON to KML?

ogr2ogr -f KML output.kml input.geojson. GDAL writes placemarks, maps name and description, and preserves other properties as ExtendedData.

Should I deliver KML or KMZ?

Deliver KMZ when the file is large or includes icons and images; it is a zipped bundle Google Earth opens directly. Keep a plain KML as your editable master, since you can read and fix it in a text editor.

Photo credits: Nemuel Sereti (Pexels); Godfrey Atima (Pexels). Photos are served from this site; follow the credit to the library page for the original.