DEV Community

Cover image for Stop Hardcoding Country Lists — Use a Proper World Geo Dataset (MySQL + JSON + CSV)
RAKSHIT SHAH
RAKSHIT SHAH

Posted on

Stop Hardcoding Country Lists — Use a Proper World Geo Dataset (MySQL + JSON + CSV)

Every developer has been there.

You need a country dropdown. So you Google "list of countries JSON", find some random gist, copy-paste it, and hope it's accurate. Then six months later a user reports that a country name is wrong, a currency code is missing, or the state list for a country only has 3 entries.

There's a better way.


What You Actually Need (And What Most Datasets Miss)

Most free country lists give you a basic name + ISO code. That's fine for simple dropdowns — but real-world apps need more:

  • 🌍 Countries — with ISO codes, phone codes, and more
  • 🗺️ States / Provinces — mapped to their parent country
  • 🏙️ Cities — mapped to states and countries
  • 💱 Currencies — with symbols and codes
  • 🗂️ Continents — for regional grouping
  • 🏷️ Zip Codes — for address validation
  • 🚩 SVG Flag Icons — for every country, ready to use in UI And you need it in a format you can actually use — not just one format.

The Dataset: What's Inside

I've been using a bundle that packages all of the above in three formats simultaneously:

├── 1. Continents → .csv / .json / .sql
├── 2. Countries  → .csv / .json / .sql + SVG flag icons
├── 3. States     → .csv / .json / .sql (with country ID mapping)
├── 4. Cities     → .csv / .json / .sql (with state + country mapping)
├── 5. Currencies → .csv / .json / .sql
└── 6. Zip Codes  → .csv / .sql
Enter fullscreen mode Exit fullscreen mode

Every file is clean, consistently structured, and ready to import.


Real Use Cases

✅ 1. Country + State Dropdown (React)

import countries from './countries.json';
import states from './states.json';

function LocationSelector() {
  const [selectedCountry, setSelectedCountry] = useState('');
  const filteredStates = states.filter(s => s.country_id === selectedCountry);

  return (
    <>
      <select onChange={e => setSelectedCountry(e.target.value)}>
        {countries.map(c => (
          <option key={c.id} value={c.id}>{c.name}</option>
        ))}
      </select>

      <select>
        {filteredStates.map(s => (
          <option key={s.id} value={s.id}>{s.name}</option>
        ))}
      </select>
    </>
  );
}
Enter fullscreen mode Exit fullscreen mode

✅ 2. Import Into MySQL in Seconds

-- Just run the .sql file:
SOURCE /path/to/countries.sql;
SOURCE /path/to/states.sql;
SOURCE /path/to/cities.sql;

-- Then query:
SELECT ci.name AS city, s.name AS state, co.name AS country
FROM cities ci
JOIN states s ON ci.state_id = s.id
JOIN countries co ON s.country_id = co.id
WHERE co.iso2 = 'IN'
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

✅ 3. Display Flags in Any Web App

<!-- SVG flags are included for all countries -->
<img src="./svg-flags/in.svg" alt="India" width="32" />
<img src="./svg-flags/us.svg" alt="USA" width="32" />
Enter fullscreen mode Exit fullscreen mode

No external dependency. No CDN. Just drop the SVG folder into your project.

✅ 4. Currency Lookup

import currencies from './currency.json';

function getCurrencySymbol(countryCode) {
  const match = currencies.find(c => c.country_code === countryCode);
  return match ? match.symbol : '$';
}

getCurrencySymbol('IN'); // ₹
getCurrencySymbol('DE'); // €
Enter fullscreen mode Exit fullscreen mode

Who Is This For?

Role How They Use It
🧑‍💻 Full-stack developers Seed databases, build location forms
🛠️ SaaS founders Add region filters, localization
🎨 UI/UX designers Prototype with real country/flag data
📊 Data analysts Geographic data for dashboards
🎓 Students / learners Practice SQL joins with real-world data

Why Not Just Use a Free API?

Free geo APIs are great — until they rate-limit you, go offline, or change their schema. Having a local, owned copy of the data means:

  • No API keys to manage
  • No rate limits
  • Works offline / in dev environments

- You control the schema

Get the Dataset

The full bundle (v2.0) with everything above — including zip codes and SVG flags — is available here:

👉 World Data Bundle on Gumroad

There are three tiers:

  • Minimal — Countries, States, Cities only
  • v1.0 Full Pack — + Continents & Currencies
  • v2.0 Advanced Full Pack — Everything including Zip Codes MIT licensed. Use it freely in personal and commercial projects.

Final Thought

Geographic data is one of those things every app eventually needs. Getting it right upfront — with clean, relational, multi-format data — saves hours of scraping, cleaning, and debugging down the road.

If you've built anything interesting with a world geo dataset, I'd love to see it in the comments. 👇


Found this useful? Drop a ❤️ or share it with a developer friend who's still copy-pasting country lists from Stack Overflow.

Top comments (0)