I am trying to validate around 100 JSON Objects against a JSON schema to see if all the fields along with the type are as per the schema or not.
Tried below JSON schema which was generated from a site. The issue with the below schema is that it does not support validation of multiple items for the "files" field as the schema is not completely correct.
Added below schema
var schema ={
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"contents": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"version": {
"type": "string"
},
"sequence": {
"type": "integer"
},
"files": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"fileName": {
"type": "string"
},
"name": {
"type": "string"
},
"fileSize": {
"type": "string"
},
"fileType": {
"type": "string"
},
"lastUpdatedDate": {
"type": "integer"
},
"fileLength": {
"type": "integer"
},
"version": {
"type": "integer"
}
},
"required": [
"fileName",
"name",
"fileSize",
"fileType",
"lastUpdatedDate",
"fileLength",
"version"
]
}
]
}
},
"required": [
"version",
"sequence",
"files"
]
}
]
}
},
"required": [
"contents"
]
}
},
"required": [
"data"
]
}
var validator = new Validator(schema)
var json=
{
"data": {
"contents": [
{
"versionn": "2021-01-15T16:01:13.475Z",
"sequence": 1,
"files": [
{
"fileName": "us-producer-price-index.txt",
"name": "us-producer-price-index",
"fileSize": "54MB",
"fileType": "txt",
"lastUpdatedDate": 1610717473000,
"fileLength": 56614933,
"version": 2
}
]
}
]
}
};
var check = validator.check(json);
console.log(check);
if(check._error==true)
{
console.log("Error in schema")
}