# Japan Railway Station API — Stations, Lines & Interchanges (`jp-data-engine/japan-railway-station-api`) Actor

Every railway station in Japan with coordinates, line, operator, prefecture and municipality code - plus the interchanges at that station. 9,059 stations, 597 lines, 178 operators, Shinkansen and tram flags. Government open data, no scraping.

- **URL**: https://apify.com/jp-data-engine/japan-railway-station-api.md
- **Developed by:** [Shota Tatara](https://apify.com/jp-data-engine) (community)
- **Categories:** Travel, Developer tools, AI
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 station rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Japan Railway Station API — Stations, Lines & Interchanges

Every railway station in Japan: where it is, which lines serve it, who runs them, and what you
can change to there.

```json
{
    "stationName": "新宿",
    "lineName": "山手線",
    "operator": "東日本旅客鉄道",
    "operatorType": "JR（在来線）",
    "railwayClass": "普通鉄道（JR）",
    "prefecture": "東京都",
    "municipality": "新宿区",
    "municipalityCode": "13104",
    "latitude": 35.68843,
    "longitude": 139.698615,
    "interchangeCount": 6,
    "connectingLines": [
        "東京都 10号線新宿線",
        "東京都 12号線大江戸線",
        "東京地下鉄 4号線丸ノ内線",
        "京王電鉄 京王線",
        "小田急電鉄 小田原線",
        "東日本旅客鉄道 中央線"
    ]
}
```

**No scraping. No API keys. No rate limits.** Compiled from Japanese government open data and
shipped inside the Actor.

***

### What is in it

|                               |                                                                                  |
| ----------------------------- | -------------------------------------------------------------------------------- |
| **9,059 stations**            | every station in Japan, from Shinkansen termini to single-platform tram stops    |
| **10,160 station-line rows**  | one per station and line, because a station served by seven lines is seven facts |
| **597 lines · 178 operators** | JR, private railways, subways, third-sector, municipal                           |
| **104 Shinkansen stations**   | flagged, not guessed from the name                                               |
| **Interchanges**              | which other lines serve the same physical station                                |

***

### What it adds to the raw data

The source (国土数値情報 鉄道) ships one line-segment per station per line, with no station
identity, no area and two numeric code columns whose meanings are easy to swap. This Actor:

- **Places the station.** Each feature is a stretch of track; the coordinate here is its
  centroid. Tokyo Station lands within 300 m of its real position — that is a regression test,
  not a claim.
- **Reconstructs interchanges** by grouping features that share 駅グループコード. That is what
  turns seven unrelated rows into "Shinjuku, served by these seven lines".
- **Adds prefecture, municipality and the 5-digit municipality code**, which the source does
  not contain at all, by matching each station to the nearest 位置参照情報 town centroid.
- **Decodes the classification columns correctly.** `N02_001` is 鉄道区分 and `N02_002` is
  事業者種別 — the opposite of what the column order suggests. Both were pinned against the
  real data: code 1 of 事業者種別 selects exactly the 104 Shinkansen rows, and 鉄道区分 25
  selects exactly the Linimo maglev.

***

### Use cases

- **Rank property by transport access.** Combine `near` with a station's `interchangeCount` to
  score any address in Japan for connectivity.
- **Build a station picker or autocomplete.** 9,059 names with coordinates, prefecture and
  municipality, in one download.
- **Join transit to any other dataset.** `municipalityCode` is the key used by every Japanese
  government statistic.
- **Answer "what is the nearest station".** A radius search returns stations sorted by distance.
- **Give an AI agent a Japan transit tool.** It runs as an MCP tool: an agent can ask "which
  lines serve this station and what is nearby" and get typed rows back.

***

### Input

```json
{
    "stationNames": ["新宿", "渋谷"],
    "lineNames": ["山手"],
    "operators": ["東日本旅客鉄道"],
    "prefectures": ["東京都"],
    "near": { "latitude": 35.6812, "longitude": 139.7671, "radiusMeters": 800 },
    "shinkansenOnly": false,
    "minInterchangeCount": 3,
    "groupByStation": true,
    "maxResults": 100
}
```

Every field is optional; an empty input returns the stations named 東京.

| Field                 | Meaning                                                                         |
| --------------------- | ------------------------------------------------------------------------------- |
| `stationNames`        | Japanese station names, matched as substrings — `新宿` also finds 西新宿        |
| `lineNames`           | Line names as substrings — `山手` finds 山手線, `新幹線` finds every Shinkansen |
| `operators`           | Operator names as substrings — `東京地下鉄` for Tokyo Metro                     |
| `prefectures`         | With or without the suffix (`東京` = `東京都`)                                  |
| `municipalityCodes`   | 5-digit 全国地方公共団体コード                                                  |
| `keyword`             | Substring across station, line, operator, prefecture and municipality           |
| `near`                | `{latitude, longitude, radiusMeters}` — sorted by distance                      |
| `shinkansenOnly`      | Shinkansen stations only                                                        |
| `minInterchangeCount` | Set to 3 or more to find the major hubs                                         |
| `groupByStation`      | One row per physical station, with all its lines in a `lines` array             |
| `maxResults`          | Hard cap on rows — this is what determines the cost of the run                  |

### Output

One row per station and line by default, or one per station with `groupByStation`.

| Field                                            | Description                                                                              |
| ------------------------------------------------ | ---------------------------------------------------------------------------------------- |
| `stationName`, `lineName`, `operator`            | As published, in Japanese                                                                |
| `operatorType`                                   | JR（新幹線）/ JR（在来線）/ 公営鉄道 / 民営鉄道 / 第三セクター                           |
| `railwayClass`                                   | 普通鉄道, 軌道, 鋼索鉄道, 懸垂式鉄道, 跨座式鉄道, 案内軌条式鉄道, 無軌条鉄道, 浮上式鉄道 |
| `isShinkansen`, `isTram`, `isMonorailOrAgt`      | Ready-made booleans for the common filters                                               |
| `stationGroupCode`                               | Shared by every line serving the same physical station                                   |
| `prefecture`, `municipality`, `municipalityCode` | Derived; the source has no area field                                                    |
| `latitude`, `longitude`                          | Centroid of the station's track geometry, WGS84                                          |
| `interchangeCount`, `connectingLines`            | The other lines at the same station                                                      |
| `distanceMeters`                                 | Radius searches only                                                                     |

***

### Pricing

Pay per event: a small charge to start the run, plus a charge per row returned. No proxy costs,
because there is nothing to proxy.

***

### Data sources

| Source                                                           | Publisher  | Licence                             |
| ---------------------------------------------------------------- | ---------- | ----------------------------------- |
| [国土数値情報 鉄道 (N02-23)](https://nlftp.mlit.go.jp/ksj/)      | 国土交通省 | 公共データ利用規約 第1.0版 (PDL1.0) |
| [位置参照情報 大字・町丁目レベル](https://nlftp.mlit.go.jp/isj/) | 国土交通省 | 公共データ利用規約 第1.0版 (PDL1.0) |

PDL1.0 permits commercial use and redistribution and requires the source credit plus a
statement that the data was edited. Reproduced here and in every run's `RUN_SUMMARY`:

> 「国土数値情報（鉄道）」（国土交通省）（https://nlftp.mlit.go.jp/ksj/）をもとに jp-data-engine が加工して作成
>
> 「位置参照情報ダウンロードサービス」（国土交通省）（https://nlftp.mlit.go.jp/isj/）をもとに jp-data-engine が加工して作成

***

### Known limits

- **Coordinates are the centroid of the track geometry**, not the station building or a
  specific entrance. For a large station like Shinjuku that is a few hundred metres from some
  exits.
- **No timetables, fares or platform data.** This is the network, not the schedule.
- **The municipality is inferred** from the nearest town centroid rather than a boundary
  polygon. It is right for stations inside a built-up area; a station on a municipal border
  can fall on the wrong side.
- **Names are Japanese only.** The source publishes no romanisation. Feed them through
  [Japan Address Normalizer, Geocoder & Romanizer](https://apify.com/jp-data-engine/japan-address-intelligence)
  if you need the coordinates turned into a romanised address.
- **Freight-only lines and closed stations** are not included; this is the passenger network as
  of the 2023 edition.

***

### Local development

```bash
npm install
npm run build:data   # downloads the government data and compiles the registry into data/
npm test             # 12 tests, including the code-mapping regressions
npx apify run
```

Part of the **jp-data-engine Japan data suite**. See also
[Japan Land Price API](https://apify.com/jp-data-engine/japan-land-price-api) — every survey
site records its nearest station, so the two join directly.

# Actor input Schema

## `stationNames` (type: `array`):

Japanese station names, matched as substrings — `新宿` also finds 西新宿 and 新宿三丁目. Leave empty to search by area instead.

## `lineNames` (type: `array`):

Japanese line names, matched as substrings — `山手` finds 山手線, `新幹線` finds every Shinkansen line.

## `operators` (type: `array`):

Operator names, matched as substrings — `東日本旅客鉄道` for JR East, `東京地下鉄` for Tokyo Metro, `近畿日本鉄道` for Kintetsu.

## `prefectures` (type: `array`):

Prefecture names, with or without the suffix — `東京` and `東京都` both work.

## `municipalityCodes` (type: `array`):

5-digit 全国地方公共団体コード, e.g. `13104` for 新宿区.

## `keyword` (type: `string`):

Case-insensitive substring across station name, line, operator, prefecture and municipality.

## `near` (type: `object`):

Find stations around a point, e.g. `{"latitude": 35.6812, "longitude": 139.7671, "radiusMeters": 800}`. Results come back sorted by distance.

## `shinkansenOnly` (type: `boolean`):

Restrict the results to Shinkansen stations.

## `minInterchangeCount` (type: `integer`):

Only return stations served by at least this many other lines. Set to 3 to find the major hubs.

## `groupByStation` (type: `boolean`):

By default you get one row per station and line. Turn this on to get one row per physical station, with all its lines in a `lines` array.

## `maxResults` (type: `integer`):

Hard cap on the number of rows written. This is what determines the cost of the run.

## Actor input object example

```json
{
  "stationNames": [
    "新宿",
    "渋谷"
  ],
  "shinkansenOnly": false,
  "groupByStation": false,
  "maxResults": 100
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `runSummary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "stationNames": [
        "新宿",
        "渋谷"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("jp-data-engine/japan-railway-station-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "stationNames": [
        "新宿",
        "渋谷",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("jp-data-engine/japan-railway-station-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "stationNames": [
    "新宿",
    "渋谷"
  ]
}' |
apify call jp-data-engine/japan-railway-station-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,jp-data-engine/japan-railway-station-api"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/HD5skgXY7k5sH6h4a/builds/TlVNKd23T1MxzzOpu/openapi.json
