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

John Carlson yottzumm at gmail.com
Fri Oct 29 22:27:16 PDT 2021


As far as JSON parsing, JavaScript is reporting (perhaps some new):

Failed JSON parse 
/c/x3d-code/www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter15Metadata/XmpMetadataEmbedded.json 
SyntaxError: Unexpected token { in JSON at position 7402
Failed JSON parse 
/c/x3d-code/www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/AudioSpatialSound/SplitChannels.json 
SyntaxError: Unexpected token { in JSON at position 6795
Failed JSON parse 
/c/x3d-code/www.web3d.org/x3d/content/examples/Savage/Scenarios/LimitedObjectiveExperimentPortHueneme/LimitedObjectiveExperimentPortHuenemeDIS.json 
SyntaxError: Unexpected string in JSON at position 11321
Failed JSON parse 
/c/x3d-code/www.web3d.org/x3d/content/examples/Savage/Scenarios/LimitedObjectiveExperimentPortHueneme/LimitedObjectiveExperimentPortHueneme.json 
SyntaxError: Unexpected string in JSON at position 10450
Failed JSON parse 
/c/x3d-code/www.web3d.org/x3d/content/examples/Savage/Locations/PanamaCityFlorida/PanamaCityGeo.json 
SyntaxError: Unexpected string in JSON at position 5200
Failed JSON parse 
/c/x3d-code/www.web3d.org/x3d/content/examples/Savage/Weapons/UnderwaterMines/SphericalMinePrototype.json 
SyntaxError: Unexpected string in JSON at position 23536

On 10/30/21 00:03, John Carlson wrote:
>
> Ajv is still failing on XMLSpy converted schema, and so is Java:
>
> Here's a smattering of errors:
>
>     [java] WARNING: Converting unescaped reference #/$defs/xs:NMTOKEN 
> to JSON Schema legal $ref form #/$defs/xs%3ANMTOKEN
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:ID to 
> JSON Schema legal $ref form #/$defs/xs%3AID
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:IDREF to 
> JSON Schema legal $ref form #/$defs/xs%3AIDREF
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:NMTOKENS 
> to JSON Schema legal $ref form #/$defs/xs%3ANMTOKENS
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:NMTOKEN 
> to JSON Schema legal $ref form #/$defs/xs%3ANMTOKEN
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:NMTOKEN 
> to JSON Schema legal $ref form #/$defs/xs%3ANMTOKEN
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:ID to 
> JSON Schema legal $ref form #/$defs/xs%3AID
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:IDREF to 
> JSON Schema legal $ref form #/$defs/xs%3AIDREF
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:NMTOKENS 
> to JSON Schema legal $ref form #/$defs/xs%3ANMTOKENS
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:NMTOKEN 
> to JSON Schema legal $ref form #/$defs/xs%3ANMTOKEN
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>     [java] WARNING: Converting unescaped reference #/$defs/xs:NMTOKEN 
> to JSON Schema legal $ref form #/$defs/xs%3ANMTOKEN
>     [java] Oct 30, 2021 12:00:39 AM 
> net.jimblackler.jsonschemafriend.PathUtils fixUnescaped
>
> Should I start filing tickets against Ajv and jsonschemafriend?
>
> Here is a small program for your use for validating with Java:
>
>
> $ cat Main.java
> import net.jimblackler.jsonschemafriend.*;
> import java.io.*;
>
> public class Main {
>  public static void main(String[] args) {
>    try {
>      SchemaStore schemaStore = new SchemaStore(); // Initialize a 
> SchemaStore.
>      // Load the schema.
>
>        // Schema schema = schemaStore.loadSchema(new 
> File("x3d-4.0-JSONSchema.json"));
>        Schema schema = schemaStore.loadSchema(new 
> File("X3dXml4.0SchemaConvertedToJson2020-12Schema.json"));
>
>        for (int a = 0; a < args.length; a++) {
>                try {
>                        new Validator().validate(schema, new 
> File(args[a]));
>                } catch (Exception ve) {
>                        ve.printStackTrace();
>                }
>        }
>    } catch (SchemaException e) {
>      e.printStackTrace();
>    }
>  }
> }
>
> On 10/29/21 23:44, John Carlson wrote:
>>
>> 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
>>
>> create_catalog('2020-12')
>>
>> # 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):
>>        try:
>>            with open(jsonname, 'r') as jsonfile:
>>                obj = json.load(jsonfile)
>>                jsonfile.close()
>>                return obj
>>        except:
>>            print(f"{jsonpre}JsonInvalid", end=" ")
>>            return None
>>
>>    # validate instance against two schemas
>>    def validate_with_schemas(self, entryPath, schemas, pres):
>>        result = [ "jsonSkipped", "jwcSkipped", "dbSkipped"]
>>
>>        try:
>>            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"
>>                schemas[si].evaluate(instance)
>>                result[si+1] = pres[si]+"Valid"
>>        except:
>>            pass
>>        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", 
>> "../schema/2020-12-JSONSchema.json"))
>>    schemafiles = ('../schema/x3d-4.0-JSONSchema.json', 
>> '../schema/X3dXml4.0SchemaConvertedToJson2020-12Schema.json')
>>    schemas = []
>>    for s in range(len(schemafiles)):
>>        schemas.append(JSONSchema(X3DJSONValidator.load_json(pre[s], 
>> schemafiles[s])))
>>        metaschema.evaluate(schemas[s])
>>    for entryPath in 
>> X3DJSONValidator.fileList("/c/x3d-code/www.web3d.org/x3d/content/examples"):
>>        X3DJSONValidator.validate_with_schemas(entryPath, schemas, pre)
>>        print(entryPath)
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20211030/08c0035f/attachment-0001.html>


More information about the x3d-public mailing list