Stream: implementers
Topic: DSTU3 JSON Schema File
Jonas Fortmann (Nov 29 2019 at 15:00):
Hi! I am trying to use the official JSON Schema for Version 3 to validate my resources and I have found many occasions where String values that are restricted by some regular expression (e.g. Timestamps) are not restricted by the schema. However, when I use the official validator.jar the string values are restricted. See e.g. the (invalid) Patient resource that I attached. It is (legitimately) not validated by the official validator, but the official json schema (illegitimately) would validate that resource (thus, so does my implementation..). I suspect it to be the same for many other datatypes that represented as strings in JSON. test_resource.json .
So the Schema that is used by the official validator does not seem to be the same schema I can download. I am confused. Can somebody help me out?
Lloyd McKenzie (Nov 29 2019 at 15:04):
The validator checks far more than JSON schema is able to. E.g. FHIRPath constraints, terminology bindings, etc. It doesn't use either the XML or JSON schemas. (Not sure why the JSON schema isn't checking regular expressions. @Grahame Grieve ?)
Jonas Fortmann (Nov 29 2019 at 15:06):
The validator checks far more than JSON schema is able to. E.g. FHIRPath constraints, terminology bindings, etc. It doesn't use either the XML or JSON schemas. (Not sure why the JSON schema isn't checking regular expressions. Grahame Grieve ?)
Thanks for the quick response. As an additional info: I have looked into the Schema Files for Version 4 and they have definitions for e.g. Instants that consequently checks the regular expression. However, they do not exist for the version 3 schema
Lloyd McKenzie (Nov 29 2019 at 15:07):
The JSON schemas were improved quite a bit as part of the R4 release. There's no intention to re-publish schemas for STU3.
Jonas Fortmann (Nov 29 2019 at 15:14):
Thanks again for the super quick responses! Hmm we are currently not able to update to R4 which means I cannot use the R4 schema files, since they wont be compatible. If I understand you correctly the Schema files only coarsely check the documented structure of the resources. In general, I do not understand the purpose of the JSON Schema files if they do not actually precisely specify the schema that is depicted in the official documentation? I understand the the real validator also checks terminology etc but shouldn't the schema files at least structurally validate a resource (precisely)? I think I got things mixed up..
Michele Mottini (Nov 29 2019 at 15:24):
The amount of work that can be done by any one person or organization is finite
Jonas Fortmann (Nov 29 2019 at 15:28):
This is absolutely correct. However, the way the schema files are presented, wrong expectations are created (At least I expected them to be precise..). Also, there seems to be a STU3 Schema file that contains this degree of precision since the official validator works just fine for STU3 also. I was thinking maybe I found the wrong files..?!
Lloyd McKenzie (Nov 29 2019 at 16:51):
JSON schema was super-new at the time STU3 came out, so the amount of work on it was limited. The validator had been worked on for much longer. The validator checks the instances after they've been converted from JSON (or XML or RDF) into an internal object model. It doesn't use the schemas, it uses the StructureDefinition resources. The StructureDefinitions are the official source of truth - all schemas, schematrons, etc. are generated from those.
Grahame Grieve (Nov 29 2019 at 17:45):
I don't mind if someone wants to prepare a more complete set of json schemas for R3. however: the whlole json schema is a mine field. I've invested way too much time trying to get a set of json schemas that work for some reasources with some tools....
John Silva (Nov 29 2019 at 20:11):
FWIW, I've had better luck with the R4 JSchema (with Newtonsoft's JSchema library) than with the R3 JSchema.
There were (and are) some RegEx patterns in R3 JSchema, e.g. for FHIR DateTime and some other datatypes and NewtownSoft does check for these patterns and rejects those that do not match.
Last updated: Apr 12 2022 at 19:14 UTC