jsonschema

app.quicktype.io

import requests

INSPECTIONS_SUMMARY_SCHEMA = {
    "$schema": "http://json-schema.org/draft-07/schema",
    "type": "object",
    "required": [
        "data",
        "last_update"
    ],
    "properties": {
        "last_update": {
            "pattern": "^[0-9]{4}\/[0-9]{2}\/[0-9]{2} [0-9]{2}:[0-9]{2}$",
            "type": "string"
        },
        "labels": {
            "type": "array",
            "items": {
                "type": "string",
                "pattern": "^[0-9]{2}/[0-9]{2}$"
            }
        },
        "data": {
            "type": "object",
            "properties": {
                "検査検体数": {
                    "type": "array",
                    "default": [],
                    "items": {
                        "type": "integer",
                        "default": 0
                    }
                },
                "陽性確認": {
                    "type": "array",
                    "default": [],
                    "items": {
                        "type": "integer",
                        "default": 0
                    }
                }
            }
        }
    }
}

PATIENTS_SUMMARY_SCHEMA = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "required": [
        "data",
        "last_update"
    ],
    "properties": {
        "last_update": {
            "pattern": "^[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}$",
            "type": "string"
        },
        "data": {
            "type": "array",
            "items": {
                "type": "object",
                "required": [
                    "日付",
                    "小計"
                ],
                "properties": {
                    "日付": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "小計": {
                        "default": 0,
                        "type": "integer"
                    }
                }
            }
        }
    }
}

!pip install jsonschema

import jsonschema

# inspections_summary.json

r = requests.get("https://raw.githubusercontent.com/stop-covid19-hyogo/covid19/development/data/inspections_summary.json")

d = r.json()

jsonschema.validate(d, INSPECTIONS_SUMMARY_SCHEMA)

# patients_summary.json

r = requests.get("https://raw.githubusercontent.com/stop-covid19-hyogo/covid19/development/data/patients_summary.json")

d = r.json()

jsonschema.validate(d, PATIENTS_SUMMARY_SCHEMA)