I have following JSON config in a typescript project. I would like to validate this on the front-end during run-time. I am looking for a solution similar to node-convict.
I need to validate
- unique
id/ No duplicate Id. - unique name.
- required property non empty
type - Multiple children types conditionally e.g. if type ===
folderthey should havechildrenprop. it can be an empty array. - Nested Objects at multiple levels.
I've found AJV. AJV docs only refer to whole object being unique not specific properties. I could potentially come up with my own and do some recursive validation. However, I am looking for most efficient solution whether using ajv, another library or an efficient data structure that I could use to validate this.
If using external library it need to be compatible with typescript. I am NOT looking for typescript compile-time validation.
[{
"type": "folder",
"name": "",
"id": 1, // UUID
"chldren": [{
"id": 11, // UUID
"type": "table", // TABLE TYPE
"name": "Some Table 1",
"meta": {},
"dataSource": "..........."
},
{
"type": "folder", // FOLDER TYPE
"name": "",
"id": 111, // UUID
"chldren": [{
"type": "folder",
"name": "",
"id": 1111, // UUID
"chldren": [{
"id": 11111, // UUID
"type": "table",
"name": "Some Another Table",
"meta": {},
"dataSource": "..........."
}]
}]
}
]
}]