API Reference

Geographic map data as a single API call

https://api.mapjson.com

Overview

mapjson returns topojson (or geojson) for any geographic layer in a single AJAX call. The shortest possible call returns 110m world countries with no attached properties — the most common use case for a world map.

// Minimal call — 110m world countries, no properties
d3.json("https://api.mapjson.com/v1/geo").then(topo => {
  const countries = topojson.feature(topo, topo.objects.geo);
  // draw your map
});

// With filtering and properties
d3.json("https://api.mapjson.com/v1/geo?layer=countries&filter=europe&detail=medium&properties=name,iso2")
  .then(topo => { /* ... */ });

Endpoint

GET/v1/geo
  ?layer=countries
  &filter=world
  &detail=low
  &properties=name,iso2,capital
  &format=topojson
Parameter Default Options Description
layer countries
countries regions districts postal lakes rivers coastlines
Which geographic layer to return. All layers return polygon or line geometry. See Layers below.
filter world
world europe asia africa north-america south-america oceania antarctica {ISO2} {ISO 3166-2} {name}
Filters output to a continent, country, or region. Accepts a continent slug, ISO alpha-2 country code (FR), ISO 3166-2 region code (US-MA), or full country name (France). Use layer=regions&filter=US to get one country's regions. Use layer=districts&filter=US for all US counties, or filter=US-MA for just Massachusetts counties. Region-level filter is required for districts — continent slugs and world are not accepted.
detail low
low medium high
Geometry resolution. See Detail Levels below.
properties none name, nameOfficial, iso2, iso3, isoNum, continent, subregion, areakm2, capital, capitalLat, capitalLng Comma-separated list of properties to attach to each feature. Only applies to the countries layer — the worker merges these from a lookup table at request time. Omit entirely for geometry-only output (smallest response). Districts and regions include gid, name, parent_gid, and iso2 by default; the properties parameter is ignored for those layers.
format topojson
topojson geojson
Output format. Topojson is smaller and faster to render. Geojson is more compatible with other tools.

Layers

countries
polygon
Sovereign countries and territories. All territories included — disputed ones carry a disputed: true property. Supports filter, detail, properties.
regions
polygon
First-level administrative divisions — US states, French departments, German Länder, Polish voivodeships, etc. Use filter=US to get one country's regions.
districts
polygon
Second-level administrative divisions — US counties, with 5-digit FIPS codes as gid for easy data joins. Use filter=US for all US counties, or filter=US-MA for a single state. The detail parameter is ignored — districts always return at high resolution.
postal
polygon
US ZIP code areas (Census 2020 ZCTAs — polygon approximations of USPS ZIP codes), with the 5-digit code as gid. A state filter is required: filter=US-MA. Served per state at 1:500k; detail is ignored. Note: PO-box-only ZIPs have no polygon, and boundaries are census approximations. Public domain (US Census Bureau).
lakes
polygon
Major lakes and inland water bodies. Supports detail.
rivers
line
Rivers and lake centerlines. Supports detail.
coastlines
line
World coastlines. Supports detail.

Detail Levels

Value Source resolution Best for Typical file size
low 110m (Natural Earth) World maps, small insets, thumbnails ~100 KB
medium 50m (Natural Earth) Continent-level maps ~300 KB
high 10m (Natural Earth) or DIVA-GIS for small countries Country and regional maps ~2 MB
When filter is an ISO alpha-2 country code and detail=high, the API automatically serves a higher-resolution file for ~60 small countries and territories (Monaco, Aruba, Singapore, Martinique, etc.) that are too small for Natural Earth 10m. No change to your API call is needed.

Properties

Only applies to the countries layer. No properties are returned by default — pass ?properties=name,iso2 to request specific fields, keeping the response as small as possible. Regions and districts include gid, name, parent_gid, and iso2 in every response automatically; passing properties has no effect on those layers.

nameShort English name (e.g. "France")
nameOfficialFormal name (e.g. "French Republic")
iso2ISO 3166-1 alpha-2 (e.g. "FR")
iso3ISO 3166-1 alpha-3 (e.g. "FRA")
isoNumISO 3166-1 numeric (e.g. "250")
continentContinent name (e.g. "Europe")
subregionSubregion (e.g. "Western Europe")
capitalCapital city name (e.g. "Paris")
capitalLatCapital latitude
capitalLngCapital longitude
areakm2Land area in km², computed from 10m Natural Earth geometry. Approximate — within ~2% of authoritative values for most countries. Useful as a denominator for density calculations (e.g. population ÷ areakm2). Returns null for very small territories below 10m resolution (e.g. Vatican City).

Examples

Minimal — world countries, 110m, no properties
https://api.mapjson.com/v1/geo
Europe countries with name and ISO code
https://api.mapjson.com/v1/geo?layer=countries&filter=europe&detail=medium&properties=name,iso2
France administrative regions (departments), high detail
https://api.mapjson.com/v1/geo?layer=regions&filter=FR&detail=high
USA states, medium detail
https://api.mapjson.com/v1/geo?layer=regions&filter=US&detail=medium
Poland voivodeships, high detail
https://api.mapjson.com/v1/geo?layer=regions&filter=PL&detail=high
World lakes, medium detail, as GeoJSON
https://api.mapjson.com/v1/geo?layer=lakes&detail=medium&format=geojson

Response

The default response is a topojson Topology object. The feature collection is always at topo.objects.geo regardless of which layer you requested. All responses include Access-Control-Allow-Origin: *.

topojson
{
  "type": "Topology",
  "objects": {
    "geo": {
      "type": "GeometryCollection",
      "geometries": [
        {
          "type": "Polygon",
          "arcs": [[0, 1, 2]],
          "properties": {
            "name": "France",
            "iso2": "FR",
            "iso3": "FRA",
            "isoNum": "250",
            "continent": "Europe",
            "capital": "Paris",
            "capitalLat": 48.8566,
            "capitalLng": 2.3515
          }
        }
        // ...
      ]
    }
  },
  "arcs": [ ... ]
}

When no properties parameter is given, each feature's properties object is empty ({}).

Format size comparison

Filtered topojson responses have unreferenced arcs pruned, making them significantly smaller than the equivalent geojson. Shared border arcs are deduplicated in topojson; geojson re-emits full floating-point coordinates for every feature independently.

Request topojson geojson
filter=FR&detail=low 765 B 2.3 KB
filter=DE&detail=high 27 KB 114 KB
filter=world&detail=low 91 KB 426 KB

Sizes are uncompressed. gzip compression narrows the gap somewhat; topojson still wins for all request types.

Identifiers

Every feature returned by the API has a stable gid property — a string key you can use to join map geometry to your own data. gid values are always present in the response, regardless of the properties parameter.

countries
ISO alpha-2 code — US, FR, DE. Matches the filter parameter values and the same codes used by virtually every external dataset.
regions
ISO 3166-2 subdivision code — US-CA, DE-BY, FR-IDF. Where Natural Earth does not carry an official ISO 3166-2 code, the HASC code is used instead (e.g. US.CA). The catalog endpoint flags which source applies.
districts
5-digit FIPS code for US counties — 06037 (Los Angeles), 36061 (Manhattan). The first two digits are the state FIPS, which maps directly to the state's ISO 3166-2 via the catalog.
postal
5-digit ZCTA code (Census ZIP Code Tabulation Area) — 02139 (Cambridge MA), 90210 (Beverly Hills). Matches the ZIP codes in your data for ~95% of use cases; parent_gid is the state's ISO 3166-2.

Hierarchy

Features below the country level carry a parent_gid property that links upward through the hierarchy. You can traverse the full tree without downloading extra geometry.

district  06037  (Los Angeles County)
  └─ region   US-CA  (California)
       └─ country  US  (United States)

The parent_gid of a region is always a country ISO alpha-2. The parent_gid of a district is always the state's ISO 3166-2.

Catalog endpoint

The catalog lists every gid in a layer with its name, parent, and all known external codes — useful for building lookup tables or crosswalks without downloading geometry.

GET /v1/catalog?layer=countries
GET /v1/catalog?layer=regions&filter=PL
GET /v1/catalog?layer=districts&filter=US
GET /v1/catalog?layer=districts&filter=US-MA

filter is required for regions, districts, and postal. Accepts the same values as /v1/geo: an ISO alpha-2 country code (US) or an ISO 3166-2 region code (US-MA) for districts. Omitting it returns an error. The countries layer ignores filter.

Returns a JSON array. Example entry for a region:

{
  "gid":        "US-CA",
  "name":       "California",
  "layer":      "regions",
  "parent_gid": "US",
  "iso2":       "US",
  "gid_source": "iso3166-2"
}

Joining to external data

The gid is chosen to match codes your data already uses. Census, CDC, BLS, and most US federal sources use 5-digit FIPS for counties — join on gid directly. For countries, ISO alpha-2 is the most widely used identifier in web APIs and statistical databases. For states and international regions, ISO 3166-2 is used by Eurostat, NUTS crosswalks, and most administrative data sources. Where a dataset uses a different code system, use the catalog to build a translation table.

Country Codes

Use these ISO alpha-2 codes with the filter parameter (e.g. filter=DE) to retrieve a specific country.

235 countries and territories

* Informal code — not officially assigned by ISO 3166-1.

ISO2 ISO3 Name
AFAFGAfghanistan
AXALAÅland
ALALBAlbania
DZDZAAlgeria
ASASMAmerican Samoa
ADANDAndorra
AOAGOAngola
AIAIAAnguilla
AQATAAntarctica
AGATGAntigua and Barb.
ARARGArgentina
AMARMArmenia
AWABWAruba
ATAUTAustria
AZAZEAzerbaijan
BSBHSBahamas
BHBHRBahrain
BDBGDBangladesh
BBBRBBarbados
BYBLRBelarus
BEBELBelgium
BZBLZBelize
BJBENBenin
BMBMUBermuda
BTBTNBhutan
BOBOLBolivia
BABIHBosnia and Herz.
BWBWABotswana
IOIOTBr. Indian Ocean Ter.
BRBRABrazil
VGVGBBritish Virgin Is.
BNBRNBrunei
BGBGRBulgaria
BFBFABurkina Faso
BIBDIBurundi
CVCPVCabo Verde
KHKHMCambodia
CMCMRCameroon
CACANCanada
KYCYMCayman Is.
CFCAFCentral African Rep.
TDTCDChad
CLCHLChile
CNCHNChina
COCOLColombia
KMCOMComoros
CGCOGCongo
CKCOKCook Is.
CRCRICosta Rica
CICIVCôte d'Ivoire
HRHRVCroatia
CUCUBCuba
CWCUWCuraçao
CYCYPCyprus
CZCZECzechia
CDCODDem. Rep. Congo
DKDNKDenmark
DJDJIDjibouti
DMDMADominica
DODOMDominican Rep.
ECECUEcuador
EGEGYEgypt
SVSLVEl Salvador
GQGNQEq. Guinea
ERERIEritrea
EEESTEstonia
SZSWZeSwatini
ETETHEthiopia
FOFROFaeroe Is.
FKFLKFalkland Is.
FJFJIFiji
FIFINFinland
PFPYFFr. Polynesia
TFATFFr. S. Antarctic Lands
GAGABGabon
GMGMBGambia
GEGEOGeorgia
DEDEUGermany
GHGHAGhana
GIGIBGibraltar
GRGRCGreece
GLGRLGreenland
GDGRDGrenada
GUGUMGuam
GTGTMGuatemala
GGGGYGuernsey
GNGINGuinea
GWGNBGuinea-Bissau
GYGUYGuyana
HTHTIHaiti
HMHMDHeard I. and McDonald Is.
HNHNDHonduras
HKHKGHong Kong
HUHUNHungary
ISISLIceland
ININDIndia
IDIDNIndonesia
IRIRNIran
IQIRQIraq
IEIRLIreland
IMIMNIsle of Man
ILISRIsrael
ITITAItaly
JMJAMJamaica
JPJPNJapan
JEJEYJersey
JOJORJordan
KZKAZKazakhstan
KEKENKenya
KIKIRKiribati
XKXKXKosovo *
KWKWTKuwait
KGKGZKyrgyzstan
LALAOLaos
LVLVALatvia
LBLBNLebanon
LSLSOLesotho
LRLBRLiberia
LYLBYLibya
LILIELiechtenstein
LTLTULithuania
LULUXLuxembourg
MOMACMacao
MGMDGMadagascar
MWMWIMalawi
MYMYSMalaysia
MVMDVMaldives
MLMLIMali
MTMLTMalta
MHMHLMarshall Is.
MRMRTMauritania
MUMUSMauritius
MXMEXMexico
FMFSMMicronesia
MDMDAMoldova
MCMCOMonaco
MNMNGMongolia
MEMNEMontenegro
MSMSRMontserrat
MAMARMorocco
MZMOZMozambique
MMMMRMyanmar
MPMNPN. Mariana Is.
NANAMNamibia
NRNRUNauru
NPNPLNepal
NLNLDNetherlands
NCNCLNew Caledonia
NZNZLNew Zealand
NINICNicaragua
NENERNiger
NGNGANigeria
NUNIUNiue
NFNFKNorfolk Island
KPPRKNorth Korea
MKMKDNorth Macedonia
OMOMNOman
PKPAKPakistan
PWPLWPalau
PSPSEPalestine
PAPANPanama
PGPNGPapua New Guinea
PYPRYParaguay
PEPERPeru
PHPHLPhilippines
PNPCNPitcairn Is.
PLPOLPoland
PTPRTPortugal
PRPRIPuerto Rico
QAQATQatar
ROROURomania
RURUSRussia
RWRWARwanda
GSSGSS. Geo. and the Is.
SSSSDS. Sudan
SHSHNSaint Helena
LCLCASaint Lucia
WSWSMSamoa
SMSMRSan Marino
STSTPSão Tomé and Principe
SASAUSaudi Arabia
SNSENSenegal
RSSRBSerbia
SCSYCSeychelles
SLSLESierra Leone
SGSGPSingapore
SXSXMSint Maarten
SKSVKSlovakia
SISVNSlovenia
SBSLBSolomon Is.
SOSOMSomalia
ZAZAFSouth Africa
KRKORSouth Korea
ESESPSpain
LKLKASri Lanka
BLBLMSt-Barthélemy
MFMAFSt-Martin
KNKNASt. Kitts and Nevis
PMSPMSt. Pierre and Miquelon
VCVCTSt. Vin. and Gren.
SDSDNSudan
SRSURSuriname
SESWESweden
CHCHESwitzerland
SYSYRSyria
CN-TWTWNTaiwan
TJTJKTajikistan
TZTZATanzania
THTHAThailand
TLTLSTimor-Leste
TGTGOTogo
TOTONTonga
TTTTOTrinidad and Tobago
TNTUNTunisia
TRTURTurkey
TMTKMTurkmenistan
TCTCATurks and Caicos Is.
TVTUVTuvalu
UMUMIU.S. Minor Outlying Is.
VIVIRU.S. Virgin Is.
UGUGAUganda
UAUKRUkraine
AEAREUnited Arab Emirates
GBGBRUnited Kingdom
USUSAUnited States of America
UYURYUruguay
UZUZBUzbekistan
VUVUTVanuatu
VAVATVatican
VEVENVenezuela
VNVNMVietnam
EHESHW. Sahara
WFWLFWallis and Futuna Is.
YEYEMYemen
ZMZMBZambia
ZWZWEZimbabwe