Skip to content

KTBsomen/Indian-state-district-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Indian States and Districts JSON Dataset (Latest, Official Source)

Data Source Format Updated Includes License

This repository provides the latest Indian states and districts JSON dataset, along with the browser-based scraper code used to generate it. The data is sourced directly from an official Indian government website and includes both the generated JSON file and the scraper code.

Source website: https://igod.gov.in/sg/district/states


Why This Repository Exists

Developers commonly search for:

  • Indian states and districts JSON
  • District list of India in JSON format
  • India state district dropdown data
  • Indian address data for forms and APIs

Most available datasets are outdated, incomplete, or not traceable to an official source. This repository solves that by enabling direct, reproducible extraction from a government portal.


What This Repository Contains

1. Ready-to-Use JSON File

  • Latest available states and districts
  • Clean, minimal structure
  • Suitable for frontend, backend, APIs, and databases

2. Browser-Based Scraper Code

  • Runs directly in the browser console
  • No Node.js or dependencies
  • No CORS issues
  • Can be re-run anytime to refresh data

Data Source

All data is extracted from the official Indian government portal:

https://igod.gov.in/sg/district/states

This ensures:

  • Authentic data
  • Verifiable source
  • Transparency
  • Long-term reliability

JSON Structure

[
  {
    "state": "West Bengal",
    "districts": [
      "Kolkata",
      "Howrah",
      "Darjeeling"
    ]
  },
  {
    "state": "Maharashtra",
    "districts": [
      "Mumbai",
      "Pune",
      "Nagpur"
    ]
  }
]

Structure Rationale

  • Flat and predictable
  • Easy to map to dropdowns
  • Simple to extend with codes or metadata
  • Language-agnostic

How to Generate the Latest Dataset

Step 1: Open the Official Website

Navigate to:

https://igod.gov.in/sg/district/states

Step 2: Open Developer Tools

  • Windows / Linux: F12 or Ctrl + Shift + I
  • macOS: Cmd + Option + I

Switch to the Console tab.


Running the Scraper

Option A: Paste Directly in Console (Default)

Paste the script below into the browser console and press Enter.

(async () => {

  const CONCURRENCY = 3; // keep low (gov server)
  const STEP = 5;
  const result = [];
  let index = 0;

  const stateLinks = Array.from(
    document.querySelectorAll(".state li a")
  ).map(a => ({
    state: a.innerText.trim(),
    url: a.href.replace("categories","E042/organizations")
  }));

  async function scrapeState(current) {

    console.log(`Fetching state page: ${current.state}`);

    const res = await fetch(current.url);
    const html = await res.text();
    const doc = new DOMParser().parseFromString(html, "text/html");

    const districts = new Set();

    // 1️⃣ Extract already loaded districts
    doc.querySelectorAll(".search-row .search-title")
      .forEach(el => districts.add(el.innerText.trim()));

    // 2️⃣ Build AJAX continuation base URL
    const urlParts = new URL(current.url).pathname.split("/");
    const sg = urlParts[1];
    const stateCode = urlParts[2];
    const category = urlParts[3];

    let start = districts.size;

    while (true) {

      const ajaxUrl = `/${sg}/${stateCode}/${category}/organizations_more/${start}/5`;

      const res2 = await fetch(ajaxUrl, {
        credentials: "same-origin",
        headers: {
          "X-Requested-With": "XMLHttpRequest"
        }
      });

      const moreHTML = await res2.text();

      if (!moreHTML || !moreHTML.trim()) {
        break;
      }

      const moreDoc = new DOMParser().parseFromString(moreHTML, "text/html");

      const newItems = moreDoc.querySelectorAll(".search-row .search-title");

      if (!newItems.length) break;

      newItems.forEach(el =>
        districts.add(el.innerText.trim())
      );

      console.log(`${current.state} → fetched ${districts.size}`);

      start += STEP;

      await new Promise(r => setTimeout(r, 400)); // polite delay
    }

    console.log(`✔ DONE: ${current.state} (${districts.size})`);

    return {
      state: current.state,
      districts: Array.from(districts)
    };
  }

  async function worker() {
    while (index < stateLinks.length) {
      const current = stateLinks[index++];
      const data = await scrapeState(current);
      result.push(data);
    }
  }

  await Promise.all(
    Array.from({ length: CONCURRENCY }, worker)
  );

  // Download JSON
  const json = JSON.stringify(result, null, 2);
  const blob = new Blob([json], { type: "application/json" });
  const downloadUrl = URL.createObjectURL(blob);

  const a = document.createElement("a");
  a.href = downloadUrl;
  a.download = "india-states-districts.json";
  a.click();

  URL.revokeObjectURL(downloadUrl);

  console.log("Download complete ✅");

})();

Option B: If Pasting Is Disabled in the Console

Some environments (managed browsers, enterprise devices, hardened profiles) disable paste in DevTools.

In that case:

  1. Type this manually in the console:

    allow pasting

    Press Enter.

  2. Paste the script again.

This is a built-in Chrome / Edge safety prompt and is expected behavior.


Option C: Manual Injection (No Paste at All)

If paste is completely blocked:

  1. Create a new Snippet in DevTools:

    • DevTools → Sources → Snippets → New Snippet
  2. Paste the code there

  3. Right-click → Run

This works even in restricted environments.


Output

The browser will automatically download:

india-states-districts-latest.json

This file reflects the current data at the time of execution.


Use Cases

  • Indian address forms
  • State and district dropdowns
  • Government and civic applications
  • College and university projects
  • Location-based filtering
  • APIs and microservices
  • Data analysis and research

Keeping the Data Updated

Districts and administrative boundaries may change.

To update:

  1. Visit the source website again
  2. Re-run the scraper
  3. Replace the JSON file in the repository

This approach ensures freshness without relying on third parties.


Accuracy and Responsibility

  • Data comes directly from a public government source
  • No automated crawling or abuse
  • Fully transparent extraction logic
  • Users should validate data for mission-critical use

License

MIT License. Free to use, modify, and distribute.


Maintainer

Maintained by Somen Das.


SEO Target Keywords

Indian states districts JSON India district list JSON Indian address dataset State district dropdown India Indian geography data Government district data India igod.gov.in districts

About

Latest Indian states and districts JSON dataset with browser-based scraper code. Data sourced from official government website and includes ready-to-use JSON file.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors