How do I generate a JSON schema in Python for the below JSON and validate every json against the schema?
Requirements:
- There is a type which can be CSV or JSON or JSON
- There is a list of properties.
- Each property has a key which is a column name and the value is a dict which defines the column attributes. The first column col1 has an attributes type string and corresponds to index zero.
{
"type": "csv/json",
"properties": {
"col1": {
"type": "string",
"index":0
},
"col2": {
"type": "number",
"index":1
},....
}
}
How do I generate a JSON schema for this json?
Sample Valid json
{
"type": "csv",
"properties": {
"header1": {
"type": "string",
"index":0
},
"header2": {
"type": "number",
"index":1
}
}
}
Sample invalid json (because the type is bool for header 1 and misses index attribute)
{
"type": "CSV",
"properties": {
"header1": {
"type": "bool"
},
"header2": {
"type": "number",
"index":1
}
}
}