{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openpostcodes.uk/schema.json",
  "title": "OpenPostcodes postcode",
  "description": "The JSON response from https://openpostcodes.uk/{postcode}.json - see https://openpostcodes.uk for the same fields as a table.",
  "type": "object",
  "properties": {
    "postcode": {
      "description": "Postcode in canonical format, with the space",
      "type": "string"
    },
    "part": {
      "description": "Postcode components",
      "type": "object",
      "properties": {
        "outcode": {
          "description": "Outward code - before the space, e.g. EC1A",
          "type": "string"
        },
        "incode": {
          "description": "Inward code - after the space, e.g. 1BB",
          "type": "string"
        },
        "area": {
          "description": "Postcode area - the leading letters, e.g. EC",
          "type": "string"
        },
        "district": {
          "description": "Outward code without any trailing sub-district letter, e.g. EC1 (of EC1A)",
          "type": "string"
        },
        "subdistrict": {
          "description": "Outward code including the trailing letter, when present, e.g. EC1A; else null",
          "type": [
            "string",
            "null"
          ]
        },
        "sector": {
          "description": "Outward code, a space, and the first inward character, e.g. EC1A 1",
          "type": "string"
        },
        "unit": {
          "description": "The last two letters of the postcode, e.g. BB",
          "type": "string"
        }
      },
      "required": [
        "outcode",
        "incode",
        "area",
        "district",
        "subdistrict",
        "sector",
        "unit"
      ]
    },
    "latitude": {
      "description": "Latitude of the postcode centroid (WGS84)",
      "type": [
        "number",
        "null"
      ]
    },
    "longitude": {
      "description": "Longitude of the postcode centroid (WGS84)",
      "type": [
        "number",
        "null"
      ]
    },
    "open_location_code": {
      "description": "Open Location Code (plus code) for the centroid",
      "type": [
        "string",
        "null"
      ]
    },
    "maidenhead_locator": {
      "description": "Maidenhead Locator (amateur radio grid square) for the centroid",
      "type": [
        "string",
        "null"
      ]
    },
    "qibla": {
      "description": "Bearing to Mecca, in degrees clockwise from true north",
      "type": [
        "number",
        "null"
      ]
    },
    "magnetic_declination": {
      "description": "Angle between true and magnetic north, in degrees east (World Magnetic Model 2025)",
      "type": [
        "number",
        "null"
      ]
    },
    "eastings": {
      "description": "OS National Grid easting, in metres",
      "type": [
        "number",
        "null"
      ]
    },
    "northings": {
      "description": "OS National Grid northing, in metres",
      "type": [
        "number",
        "null"
      ]
    },
    "grid_reference": {
      "description": "OS grid reference - British National Grid, or Irish Grid for Northern Ireland",
      "type": [
        "string",
        "null"
      ]
    },
    "utm": {
      "description": "Universal Transverse Mercator coordinate for the centroid - zone, MGRS latitude band, easting and northing, e.g. \"30U 479645 5621910\"",
      "type": [
        "string",
        "null"
      ]
    },
    "antipode": {
      "description": "The point diametrically opposite on the earth's surface",
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "latitude": {
          "description": "Latitude of the antipode (WGS84)",
          "type": "number"
        },
        "longitude": {
          "description": "Longitude of the antipode (WGS84)",
          "type": "number"
        }
      },
      "required": [
        "latitude",
        "longitude"
      ]
    },
    "elevation": {
      "description": "Ground elevation at the centroid, in metres (GB mainland; OS Terrain 50)",
      "type": [
        "number",
        "null"
      ]
    },
    "timezone": {
      "description": "IANA timezone (Europe/London, or the Crown Dependency zone)",
      "type": "string"
    },
    "sun": {
      "description": "Today's solar times at the centroid, as local ISO 8601 timestamps to the minute",
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "rise": {
          "description": "Sunrise - the sun's upper limb at the horizon, allowing for refraction",
          "type": [
            "string",
            "null"
          ]
        },
        "noon": {
          "description": "Solar noon - the sun crossing the meridian, at its highest point of the day",
          "type": "string"
        },
        "set": {
          "description": "Sunset",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "rise",
        "noon",
        "set"
      ]
    },
    "country": {
      "description": "Country as { name, code }. name ∈ England, Scotland, Wales, Northern Ireland, Channel Islands, Isle of Man; code is the GSS code",
      "$ref": "#/$defs/named_code"
    },
    "region": {
      "description": "Region as { name, code } (GSS). England only; both null elsewhere",
      "$ref": "#/$defs/named_code"
    },
    "admin_district": {
      "description": "Local authority district as { name, code } (GSS)",
      "$ref": "#/$defs/named_code"
    },
    "ward": {
      "description": "Electoral ward as { name, code } (GSS)",
      "$ref": "#/$defs/named_code"
    },
    "constituency": {
      "description": "Westminster parliamentary constituency as { name, code } (GSS)",
      "$ref": "#/$defs/named_code"
    },
    "county": {
      "description": "County as { name, code } (GSS); both null where the postcode is not in a county",
      "$ref": "#/$defs/named_code"
    },
    "parish_code": {
      "description": "Civil parish (or community) GSS code",
      "type": [
        "string",
        "null"
      ]
    },
    "census": {
      "description": "2011 & 2021 census statistical geographies (GSS codes)",
      "type": "object",
      "properties": {
        "oa21": {
          "description": "2021 Census Output Area code",
          "type": [
            "string",
            "null"
          ]
        },
        "lsoa21": {
          "description": "2021 Lower Layer Super Output Area code",
          "type": [
            "string",
            "null"
          ]
        },
        "msoa21": {
          "description": "2021 Middle Layer Super Output Area code",
          "type": [
            "string",
            "null"
          ]
        },
        "msoa_name": {
          "description": "MSOA friendly name (House of Commons Library; England & Wales)",
          "type": [
            "string",
            "null"
          ]
        },
        "oa11": {
          "description": "2011 Census Output Area code",
          "type": [
            "string",
            "null"
          ]
        },
        "lsoa11": {
          "description": "2011 Lower Layer Super Output Area code",
          "type": [
            "string",
            "null"
          ]
        },
        "msoa11": {
          "description": "2011 Middle Layer Super Output Area code",
          "type": [
            "string",
            "null"
          ]
        },
        "workplace_zone_code": {
          "description": "2011 Workplace Zone code",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "oa21",
        "lsoa21",
        "msoa21",
        "msoa_name",
        "oa11",
        "lsoa11",
        "msoa11",
        "workplace_zone_code"
      ]
    },
    "classification": {
      "description": "Area classifications and indices",
      "type": "object",
      "properties": {
        "rural_urban": {
          "description": "Rural/urban classification, decoded to text",
          "type": [
            "string",
            "null"
          ]
        },
        "rural_urban_code": {
          "description": "Rural/urban classification code (e.g. RLN1, or 1-6 in Scotland)",
          "type": [
            "string",
            "null"
          ]
        },
        "output_area_classification": {
          "description": "2011 Output Area Classification as { name, code } (UK-wide) - supergroup name and code, e.g. 1B1",
          "$ref": "#/$defs/named_code"
        },
        "imd": {
          "description": "Deprivation rank on the relevant country's own index and scale - England's IMD, Scotland's SIMD, Wales's WIMD or Northern Ireland's NIMDM (not comparable across countries); 1 = most deprived; null for the Channel Islands and Isle of Man, which have none",
          "type": [
            "number",
            "null"
          ]
        },
        "user_type": {
          "description": "Postcode user type - “Small” (mostly residential) or “Large”",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "rural_urban",
        "rural_urban_code",
        "output_area_classification",
        "imd",
        "user_type"
      ]
    },
    "health": {
      "description": "NHS geographies (England; GSS codes)",
      "type": "object",
      "properties": {
        "nhs_region_code": {
          "description": "NHS England region code",
          "type": [
            "string",
            "null"
          ]
        },
        "icb_location_code": {
          "description": "Integrated Care Board sub-location code",
          "type": [
            "string",
            "null"
          ]
        },
        "integrated_care_board_code": {
          "description": "Integrated Care Board code",
          "type": [
            "string",
            "null"
          ]
        },
        "cancer_alliance_code": {
          "description": "Cancer Alliance code",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "nhs_region_code",
        "icb_location_code",
        "integrated_care_board_code",
        "cancer_alliance_code"
      ]
    },
    "travel_to_work_area_code": {
      "description": "Travel to Work Area GSS code",
      "type": [
        "string",
        "null"
      ]
    },
    "police_force_area_code": {
      "description": "Police Force Area GSS code",
      "type": [
        "string",
        "null"
      ]
    },
    "national_park_code": {
      "description": "National Park GSS code; null when not in a park",
      "type": [
        "string",
        "null"
      ]
    },
    "built_up_area_code": {
      "description": "Built-Up Area (2024) GSS code",
      "type": [
        "string",
        "null"
      ]
    },
    "county_electoral_division_code": {
      "description": "County Electoral Division code (two-tier county areas)",
      "type": [
        "string",
        "null"
      ]
    },
    "european_electoral_region": {
      "description": "European Electoral Region as { name, code } (legacy geography)",
      "$ref": "#/$defs/named_code"
    },
    "date_introduced": {
      "description": "Month the postcode was introduced, as YYYY-MM",
      "type": [
        "string",
        "null"
      ]
    },
    "nearest": {
      "type": "object",
      "properties": {
        "railway_station": {
          "description": "Nearest railway station (National Rail, or Translink in Northern Ireland; excludes London Underground and light rail/trams); code is the CRS code where available",
          "anyOf": [
            {
              "$ref": "#/$defs/coded_poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "hospital": {
          "description": "Nearest hospital (CQC-registered in England, or from a hand-compiled HSC Trust list in Northern Ireland)",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "gp": {
          "description": "Nearest GP surgery (CQC-registered in England, or BSO-registered in Northern Ireland)",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "school": {
          "description": "Nearest school (Get Information About Schools in England, or the Scottish Government's school roll in Scotland); no source in scope for Wales or Northern Ireland, which are null",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "airport": {
          "description": "Nearest airport; code is the IATA code",
          "anyOf": [
            {
              "$ref": "#/$defs/coded_poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "bus_stop": {
          "description": "Nearest bus stop (NaPTAN, or Translink in Northern Ireland)",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "foodbank": {
          "description": "Nearest food bank (Give Food)",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "defibrillator": {
          "description": "Nearest public-access defibrillator (The Circuit / BHF)",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "pharmacy": {
          "description": "Nearest pharmacy (OpenStreetMap)",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "post_office": {
          "description": "Nearest post office (OpenStreetMap)",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "library": {
          "description": "Nearest library (OpenStreetMap)",
          "anyOf": [
            {
              "$ref": "#/$defs/poi"
            },
            {
              "type": "null"
            }
          ]
        },
        "coast": {
          "description": "Nearest point on the coast - { distance, latitude, longitude } or null",
          "anyOf": [
            {
              "$ref": "#/$defs/point"
            },
            {
              "type": "null"
            }
          ]
        },
        "london": {
          "description": "Straight-line distance to central London (Trafalgar Square) - { distance, latitude, longitude } or null",
          "anyOf": [
            {
              "$ref": "#/$defs/point"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "railway_station",
        "hospital",
        "gp",
        "school",
        "airport",
        "bus_stop",
        "foodbank",
        "defibrillator",
        "pharmacy",
        "post_office",
        "library",
        "coast",
        "london"
      ]
    },
    "utilities": {
      "type": "object",
      "properties": {
        "electricity": {
          "description": "Electricity DNO; null outside GB and Northern Ireland (e.g. Channel Islands, Isle of Man)",
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "name": {
              "description": "Distribution Network Operator name",
              "type": "string"
            },
            "region_code": {
              "description": "MPAN distributor id, letter form (A-P); null for Northern Ireland, which doesn't use GB's MPAN numbering",
              "type": [
                "string",
                "null"
              ]
            },
            "mpan_id": {
              "description": "MPAN distributor id, number form (10-23) - the same distributor as region_code; null for Northern Ireland",
              "type": [
                "number",
                "null"
              ]
            }
          },
          "required": [
            "name",
            "region_code",
            "mpan_id"
          ]
        },
        "water": {
          "description": "Water supply undertaker",
          "type": [
            "string",
            "null"
          ]
        },
        "sewerage": {
          "description": "Sewerage services undertaker (often, but not always, the same company as utilities.water)",
          "type": [
            "string",
            "null"
          ]
        },
        "broadband": {
          "description": "Fixed broadband coverage (Ofcom Connected Nations, postcode level); null where Ofcom has no matching record for this postcode",
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "gigabit": {
              "description": "% of premises with a gigabit-capable service available",
              "type": "number"
            },
            "superfast": {
              "description": "% of premises with superfast broadband (SFBB, >=30Mbit/s) available",
              "type": "number"
            },
            "ultrafast": {
              "description": "% of premises with ultrafast broadband (UFBB, >=300Mbit/s) available",
              "type": "number"
            },
            "below_uso": {
              "description": "% of premises below the Universal Service Obligation (<10Mbit/s download or <1Mbit/s upload, from fixed broadband, a WISP or mobile FWA)",
              "type": "number"
            }
          },
          "required": [
            "gigabit",
            "superfast",
            "ultrafast",
            "below_uso"
          ]
        }
      },
      "required": [
        "electricity",
        "water",
        "sewerage",
        "broadband"
      ]
    },
    "adjacent": {
      "description": "Bordering postcodes",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "boundary": {
      "description": "Approximate postcode boundary as a GeoJSON geometry ({ type, coordinates }, WGS84); Great Britain only - null for Northern Ireland, the Channel Islands and Isle of Man",
      "anyOf": [
        {
          "$ref": "#/$defs/geometry"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "postcode",
    "part",
    "latitude",
    "longitude",
    "open_location_code",
    "maidenhead_locator",
    "qibla",
    "magnetic_declination",
    "eastings",
    "northings",
    "grid_reference",
    "utm",
    "antipode",
    "elevation",
    "timezone",
    "sun",
    "country",
    "region",
    "admin_district",
    "ward",
    "constituency",
    "county",
    "parish_code",
    "census",
    "classification",
    "health",
    "travel_to_work_area_code",
    "police_force_area_code",
    "national_park_code",
    "built_up_area_code",
    "county_electoral_division_code",
    "european_electoral_region",
    "date_introduced",
    "nearest",
    "utilities",
    "adjacent",
    "boundary"
  ],
  "$defs": {
    "named_code": {
      "description": "A geography as { name, code }",
      "type": "object",
      "properties": {
        "name": {
          "description": "Name, or null where unknown or not applicable",
          "type": [
            "string",
            "null"
          ]
        },
        "code": {
          "description": "ONS GSS code, or null where not applicable",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "name",
        "code"
      ]
    },
    "point": {
      "description": "A point, with its distance from the postcode centroid",
      "type": "object",
      "properties": {
        "distance": {
          "description": "Straight-line distance from the postcode centroid, in metres",
          "type": "number"
        },
        "latitude": {
          "description": "Latitude of the point (WGS84)",
          "type": "number"
        },
        "longitude": {
          "description": "Longitude of the point (WGS84)",
          "type": "number"
        }
      },
      "required": [
        "distance",
        "latitude",
        "longitude"
      ]
    },
    "poi": {
      "description": "A nearby point of interest",
      "type": "object",
      "properties": {
        "name": {
          "description": "Name of the point of interest",
          "type": "string"
        },
        "distance": {
          "description": "Straight-line distance from the postcode centroid, in metres",
          "type": "number"
        },
        "latitude": {
          "description": "Latitude of the point (WGS84)",
          "type": "number"
        },
        "longitude": {
          "description": "Longitude of the point (WGS84)",
          "type": "number"
        }
      },
      "required": [
        "name",
        "distance",
        "latitude",
        "longitude"
      ]
    },
    "coded_poi": {
      "description": "A nearby point of interest that carries a reference code",
      "type": "object",
      "properties": {
        "name": {
          "description": "Name of the point of interest",
          "type": "string"
        },
        "code": {
          "description": "Reference code, or null where the source has none for this one",
          "type": [
            "string",
            "null"
          ]
        },
        "distance": {
          "description": "Straight-line distance from the postcode centroid, in metres",
          "type": "number"
        },
        "latitude": {
          "description": "Latitude of the point (WGS84)",
          "type": "number"
        },
        "longitude": {
          "description": "Longitude of the point (WGS84)",
          "type": "number"
        }
      },
      "required": [
        "name",
        "code",
        "distance",
        "latitude",
        "longitude"
      ]
    },
    "geometry": {
      "description": "A GeoJSON geometry (RFC 7946) in WGS84",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "Polygon",
            "MultiPolygon"
          ]
        },
        "coordinates": {
          "type": "array"
        }
      },
      "required": [
        "type",
        "coordinates"
      ]
    }
  }
}