I am trying to reference all nested properties as string regardless of name.
An example of the data looks like this (except with a bunch of columns):
[
{
"var_1": "some_string",
"var_2": {
"col_1": "x",
"col_2": "y",
"col_3": "z"
},
"var_3": "another_string"
}
]
I used a yaml to json converter and got the following json but my process to flatten the file does not seem to get the nested information.
{
"$id": "main.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "some data",
"type": "object",
"properties": {
"var_1": {
"$ref": "another_schema.json#/definitions/var_1"
},
"var_2": {
"type": "object",
"properties": {
"fieldNames": {
"uniqueItems": true,
"type": "array",
"items": {
"type": "string"
}
}
}
},
"var_3": {
"type": "string",
"description": "another variable"
}
}
}
Is there another way to reference all the variables/items inside of fields/fieldNames (col_1, col_2, col_3)
I assume that you want to enforce that all properties under
var_2are of typestring. I can think of 2 ways of doing that:additionalPropertieswith additional constraints, concretely"type": "string":patternPropertiesmatching all field names (".*"). Here you define constraints for a regex matching against the field names (.*will match all field names), concretely:Putting both into one schema (and adding the fact that your content starts with an array) would give you this:
Will validate this:
But fail this: