I have a list of items in an array as below:
students:
schoolName: "Maroubra Public"
isEnrolled: true
details:
- name: sam
- name: david
- name: daniel
- name: terrence
- name: sylvia
- name: annie
- name: rob
- name: john
I now another list for library membership and I would like to make sure that students requested for membership are within the previous list of students.
libMembership:
- membershipType: gold
members:
- name: daniel
- name: sylvia
- name: emmanuel
I would like to the JSON schema validation failed because the name emmanuel
in libMembership.members
is not present in the students.details
In order to validate in the JSON schema, I used enum
and tried various ways to reference students.details
dynamically but nothing seemed to have worked for me, like so:
"enum": ["$data/students/details/*/name"]
The error I have been getting like:
<class 'jsonschema.exceptions.ValidationError'> 'emmanuel' is not one of ['$data/students/details/*/name']
It seems to have only picked up the invalid name but does not identify the wildcard to reference to the student names in the details (first list)
I have a list of items in an array as below:
students:
schoolName: "Maroubra Public"
isEnrolled: true
details:
- name: sam
- name: david
- name: daniel
- name: terrence
- name: sylvia
- name: annie
- name: rob
- name: john
I now another list for library membership and I would like to make sure that students requested for membership are within the previous list of students.
libMembership:
- membershipType: gold
members:
- name: daniel
- name: sylvia
- name: emmanuel
I would like to the JSON schema validation failed because the name emmanuel
in libMembership.members
is not present in the students.details
In order to validate in the JSON schema, I used enum
and tried various ways to reference students.details
dynamically but nothing seemed to have worked for me, like so:
"enum": ["$data/students/details/*/name"]
The error I have been getting like:
<class 'jsonschema.exceptions.ValidationError'> 'emmanuel' is not one of ['$data/students/details/*/name']
It seems to have only picked up the invalid name but does not identify the wildcard to reference to the student names in the details (first list)
Share Improve this question edited Feb 14 at 15:40 Jeremy Fiel 3,2972 gold badges11 silver badges25 bronze badges asked Feb 14 at 4:35 Sam AffanSam Affan 11 Answer
Reset to default 0Referencing instance data like this isn't supported out of the box with JSON Schema, however you can do it if you're in .Net by using JsonSchema.Net (my library) and its extension JsonSchema.Net.Data. You can see an example here.
If you want to play with it first, you can use my playground: https://json-everything/json-schema.