[x3d-public] JSON Schema meeting minutes Python Success!

John Carlson yottzumm at gmail.com
Fri Oct 29 21:44:24 PDT 2021

I was able to change Python validators, and the new one validates with 
XMLSpy converted schemas!  Woohoo!

Here's the main test script that I use, which I will check in:

import os
from jschon import create_catalog, JSON, JSONSchema
import json


# validate the X3D Resources examples with draft 2020-12 JSON schema
# validate one instance "instance" against X3D JSON Schema 4.0

class ValidateX3DJSON:
    # load a JSON file called jsonname into obj

    def load_json(self, jsonpre, jsonname):
            with open(jsonname, 'r') as jsonfile:
                obj = json.load(jsonfile)
                return obj
            print(f"{jsonpre}JsonInvalid", end=" ")
            return None

    # validate instance against two schemas
    def validate_with_schemas(self, entryPath, schemas, pres):
        result = [ "jsonSkipped", "jwcSkipped", "dbSkipped"]

            result[0] = "jsonDidNotParse"
            instance = JSON(self.load_json("x3d", entryPath))
            result[0] = "jsonParsed"
            for si in range(len(schemas)):
                result[si+1] = pres[si]+"Invalid"
                result[si+1] = pres[si]+"Valid"
        print(result[0], result[1], result[2], end=" ")

    def fileList(self, dirpath):
        for base, directories, filenames in list(os.walk(dirpath)):
            for filename in filenames:
                if filename.endswith(".json"):
                    fullpath = os.path.join(base, filename)
                    yield fullpath

if __name__ == "__main__":
    X3DJSONValidator = ValidateX3DJSON()
    pre = ["jwc", "db"]
    metaschema = JSONSchema(X3DJSONValidator.load_json("meta", 
    schemafiles = ('../schema/x3d-4.0-JSONSchema.json', 
    schemas = []
    for s in range(len(schemafiles)):
    for entryPath in 
        X3DJSONValidator.validate_with_schemas(entryPath, schemas, pre)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20211029/20be8791/attachment-0001.html>

More information about the x3d-public mailing list