-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_dcat_json.py
47 lines (42 loc) · 1.38 KB
/
validate_dcat_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Validates DCAT JSON against a schema.
"""
import json
import jsonschema
from jsonschema import validate
# Define a simple DCAT schema
dcat_schema = {
"type": "object",
"properties": {
"@context": {"type": "object"},
"@type": {"type": "string"},
"title": {"type": "string"},
"description": {"type": "string"},
"dataset": {
"type": "array",
"items": {
"type": "object",
"properties": {
"@type": {"type": "string"},
"name": {"type": "string"},
"title": {"type": "string"},
"description": {"type": "string"},
"identifier": {"type": "string"},
"author": {"type": "string"},
"distribution": {
"type": "array",
"items": {"type": "object"}
}
},
"required": ["@type", "name", "title", "description", "identifier", "author"]
}
}
},
"required": ["@context", "@type", "title", "description", "dataset"]
}
def validate_dcat_json(dcat_json):
try:
validate(instance=dcat_json, schema=dcat_schema)
except jsonschema.exceptions.ValidationError as err:
return f"Error validating DCAT JSON: {err.message}"
return None