-
Notifications
You must be signed in to change notification settings - Fork 3
Validating the JSON manifest using the official schema
Giacomo Marchioro edited this page Sep 10, 2021
·
2 revisions
pyIIIFpres does its best to prevent any error but it is wise to check if the resulting .json is valid using the official IIIF API 3.0 schema provided by Glen Robson and IIIF Consortium that can be found here.
A possible solution could take advantage of jsonschema
python package:
# json schema is availabe here https://github.com/IIIF/presentation-validator/blob/master/schema/iiif_3_0.json
# we can use jsonschema module for vallidating
# to install it you can use pip install jsonschema
import os
import jsonschema
import json
if not os.path.exists('iiif_3_0.json'):
import urllib.request
jsonchemadownloadurl = r"https://raw.githubusercontent.com/IIIF/presentation-validator/master/schema/iiif_3_0.json"
with urllib.request.urlopen(jsonchemadownloadurl) as response, open("iiif_3_0.json", 'wb') as out_file:
data = response.read()
out_file.write(data)
to_be_tested = "example_manifest_response.json"
with open(to_be_tested) as instance, open("iiif_3_0.json") as schema:
jsonschema.validate(instance=json.load(instance),schema=json.load(schema))