I am using the following json schema to validate json. When I have more than one elements in the array of “appData” in the json, it validates only the first “appData” in the “appData” array, i.e. the json schema validates only appData[0]. The rest like appData[1], appData[2] are not validated. Is it that “prefixItems” validates only the first element of the array?
<code>{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"appName": {
"type": "string"
},
"appData": {
"type": "array",
"prefixItems": [
{
"type": "object",
"properties": {
"appReference": {
"type": "string"
},
"tableName": {
"type": "string"
},
"beginDate": {
"type": "string",
"pattern": "^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$",
"description": "Use regex to validate this string as a date"
},
"isTrueBeginDate": {
"type": "string"
},
"paid": {
"type": "string"
},
"amount": {
"type": "null"
}
},
"required": [
"appReference",
"tableName",
"beginDate",
"paid",
"amount"
]
}
]
}
},
"required": [
"appName",
"appData"
]
}
</code>
<code>{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"appName": {
"type": "string"
},
"appData": {
"type": "array",
"prefixItems": [
{
"type": "object",
"properties": {
"appReference": {
"type": "string"
},
"tableName": {
"type": "string"
},
"beginDate": {
"type": "string",
"pattern": "^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$",
"description": "Use regex to validate this string as a date"
},
"isTrueBeginDate": {
"type": "string"
},
"paid": {
"type": "string"
},
"amount": {
"type": "null"
}
},
"required": [
"appReference",
"tableName",
"beginDate",
"paid",
"amount"
]
}
]
}
},
"required": [
"appName",
"appData"
]
}
</code>
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"appName": {
"type": "string"
},
"appData": {
"type": "array",
"prefixItems": [
{
"type": "object",
"properties": {
"appReference": {
"type": "string"
},
"tableName": {
"type": "string"
},
"beginDate": {
"type": "string",
"pattern": "^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$",
"description": "Use regex to validate this string as a date"
},
"isTrueBeginDate": {
"type": "string"
},
"paid": {
"type": "string"
},
"amount": {
"type": "null"
}
},
"required": [
"appReference",
"tableName",
"beginDate",
"paid",
"amount"
]
}
]
}
},
"required": [
"appName",
"appData"
]
}
I am using the following maven dependency to validate the json in java.
<code><dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.4.0</version>
</dependency>
</code>
<code><dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.4.0</version>
</dependency>
</code>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.4.0</version>
</dependency>