{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://konkursradarn.se/data/konkursstatistik.schema.json",
 "title": "Konkursradarn – konkursstatistik för Sverige",
 "description": "Öppet, bara läsande flöde med officiell konkursstatistik från Tillväxtanalys: antal konkurser och antal anställda berörda per månad för hela riket, varje län, varje kommun och varje bransch. Bara aggregerade antal, inga uppgifter om enskilda företag eller personer.",
 "type": "object",
 "required": ["$schema", "sajt", "url", "beskrivning", "utgivare", "genererad", "hamtad", "kalla", "innehall", "forklaring", "uppdateras", "perioder", "riket", "lan", "kommun", "bransch"],
 "additionalProperties": false,
 "properties": {
  "$schema": {"type": "string", "pattern": "^https://"},
  "sajt": {"type": "string"},
  "url": {"type": "string", "pattern": "^https://"},
  "beskrivning": {"type": "string"},
  "utgivare": {"type": "string", "description": "bolag och organisationsnummer"},
  "kontakt": {"type": "string", "description": "kontakt för frågor och rättelser"},
  "genererad": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "datum då filen byggdes"},
  "hamtad": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "datum då statistiken senast hämtades från Tillväxtanalys"},
  "kalla": {
   "type": "object", "required": ["namn", "url", "databas"], "additionalProperties": false,
   "properties": {"namn": {"type": "string"}, "url": {"type": "string", "pattern": "^https://"}, "databas": {"type": "string", "pattern": "^https://"}}
  },
  "innehall": {"type": "string"},
  "forklaring": {"type": "object", "additionalProperties": {"type": "string"}},
  "uppdateras": {"type": "string"},
  "perioder": {"type": "array", "items": {"type": "string", "pattern": "^\\d{4}M(0[1-9]|1[0-2])$"}},
  "riket": {
   "type": "object",
   "required": ["namn", "url", "kalla_tabeller", "kalla_url", "hamtad", "konkurser", "anstallda", "ar", "ar_kalla_tabell"],
   "additionalProperties": false,
   "properties": {
    "namn": {"type": "string"}, "url": {"type": "string", "pattern": "^https://"},
    "kalla_tabeller": {"$ref": "#/$defs/tabeller"}, "kalla_url": {"$ref": "#/$defs/urler"},
    "hamtad": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
    "konkurser": {"$ref": "#/$defs/serie"}, "anstallda": {"$ref": "#/$defs/serie"},
    "ar": {"type": "array", "items": {
     "type": "object", "required": ["ar", "konkurser"], "additionalProperties": false,
     "properties": {"ar": {"type": "string", "pattern": "^\\d{4}$"}, "konkurser": {"type": ["integer", "null"]}, "anstallda": {"type": ["integer", "null"]},
                    "ackord": {"type": ["integer", "null"]}, "anstallda_ackord": {"type": ["integer", "null"]}}}},
    "ar_kalla_tabell": {"type": "string", "pattern": "\\.px$"}
   }
  },
  "lan": {"type": "array", "items": {
   "type": "object",
   "required": ["kod", "namn", "url", "kalla_tabeller", "kalla_url", "hamtad", "konkurser", "anstallda"],
   "additionalProperties": false,
   "properties": {
    "kod": {"type": "string", "pattern": "^\\d{2}$", "description": "länskod"},
    "namn": {"type": "string"}, "url": {"type": "string", "pattern": "^https://konkursradarn\\.se/lan/"},
    "kalla_tabeller": {"$ref": "#/$defs/tabeller"}, "kalla_url": {"$ref": "#/$defs/urler"},
    "hamtad": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
    "konkurser": {"$ref": "#/$defs/serie"}, "anstallda": {"$ref": "#/$defs/serie"}
   }
  }},
  "kommun": {"type": "array", "items": {
   "type": "object",
   "required": ["kod", "lan", "namn", "url", "kalla_tabeller", "kalla_url", "hamtad", "konkurser", "anstallda", "bransch_12m"],
   "additionalProperties": false,
   "properties": {
    "kod": {"type": "string", "pattern": "^\\d{4}$", "description": "kommunkod"},
    "lan": {"type": "string", "pattern": "^\\d{2}$", "description": "länskod"},
    "namn": {"type": "string"}, "url": {"type": "string", "pattern": "^https://konkursradarn\\.se/kommun/"},
    "kalla_tabeller": {"$ref": "#/$defs/tabeller"}, "kalla_url": {"$ref": "#/$defs/urler"},
    "hamtad": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
    "konkurser": {"$ref": "#/$defs/serie"}, "anstallda": {"$ref": "#/$defs/serie"},
    "bransch_12m": {"type": "object", "additionalProperties": {"type": "integer", "minimum": 0}, "description": "konkurser per bransch-id senaste 12 månaderna"}
   }
  }},
  "bransch": {"type": "array", "items": {
   "type": "object",
   "required": ["id", "sni", "namn", "url", "kalla_tabeller", "kalla_url", "hamtad", "konkurser", "anstallda"],
   "additionalProperties": false,
   "properties": {
    "id": {"type": "string"}, "sni": {"type": ["string", "null"], "description": "SNI 2007-koder, null för ospecificerad bransch"},
    "namn": {"type": "string"}, "url": {"type": "string", "pattern": "^https://konkursradarn\\.se/bransch/"},
    "kalla_tabeller": {"$ref": "#/$defs/tabeller"}, "kalla_url": {"$ref": "#/$defs/urler"},
    "hamtad": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
    "konkurser": {"$ref": "#/$defs/serie"}, "anstallda": {"$ref": "#/$defs/serie"}
   }
  }}
 },
 "$defs": {
  "serie": {"type": "object", "description": "värde per månad (ÅÅÅÅMmm); null om värde saknas", "propertyNames": {"pattern": "^\\d{4}M(0[1-9]|1[0-2])$"}, "additionalProperties": {"type": ["integer", "null"], "minimum": 0}},
  "tabeller": {"type": "array", "items": {"type": "string", "pattern": "\\.px$"}},
  "urler": {"type": "array", "items": {"type": "string", "pattern": "^https://statistik\\.tillvaxtanalys\\.se/"}}
 }
}
