Validation JSON
JSON Schema has several purposes, one of which is JSON instance validation.
Example JSON 1:
{ "initValidation": [{ "id" : "notEquals", "field" : "INVESTMENT_DATA.INVESTMENT_TYPE", "value" : 8 }] }
Example JSON 2:
{ "initValidation": [{ "id" : "or", "conditions" : [{ "id" : "contains", "field" : "tablename.columnname", "value" : "columnname value" }, { "id" : "equals", "field" : "tablename.columnname", "value" : "columnname value", "ignoreCase" : "true" }] }] }
The JSON evaluators that are used within Request Modeler are shown in the following table:
Evaluator | JSON Script | Description |
---|---|---|
AndEvaluator | { "id" : "and", "conditions" : [{ //Provide the spec for an evaluation condition }, { //Provide the spec for an evaluation condition }] } | This is used to evaluate an 'And' condition. It evaluates if all the evaluators within the conditions are satisfied or not. |
ContainsEvaluator | { "id" : "contains", "field" : "The field to be validated", //The value that should be used to //validate this condition. "value" : "" } | This does a 'contains' evaluation. This is applicable only for a String field. It evaluates if the specified field contains the string within the condition or not. |
EqualsEvaluator | { "id" : "equals", "field" : "The field to be validated", "value" : "The value to be compared with", /* Optional configuration to indicate * whether the comparison should happen in * a case insensitive manner. By default * is 'false'.*/ "ignoreCase" : true } | This evaluator evaluates an '=' condition. It evaluates if the specified field is equal to the value mentioned within the condition or not. |
GreaterthanEvaluator | { "id" : "greaterthan", "field" : "The field to be validated", "value" : "The value to be compared with", // configuration for datatype "type" : "number||date" } | This evaluator evaluates an '>' condition. It evaluates if the value in the specified field is greater than the value provided within the condition or not. It enables you to select the data type as number or date as well. |
InEvaluator | { "id" : "in", "field" : "The field to be validated", "values" : ["The value to be compared with", "Another value to be compared with"], // Optional configuration to indicate whether // the comparison should happen in a case // insensitive manner. By default is 'false'. "ignoreCase" : true } | This does an 'In' evaluation. This converts the field data to a string representation and does the 'in' check. It evaluates if the field value is available in the user defined (comma separated) value provided within the validation JSON or condition. |
LesserthanEvaluator | { "id" : "lesserthan", "field" : "The field to be validated", "value" : "The value to be compared with", "type" : "number date" // configuration for datatype } | This evaluator evaluates an '<' condition. It evaluates if the value in the specified field is lesser than the value provided within the condition or not. It enables you to select the data type as number or date as well. |
NotEqualsEvaluator | { "id" : "notEquals", "field" : "The field to be validated", "value" : "The value to be compared with", // Optional configuration to indicate whether // the comparison should happen in a case // insensitive manner. By default is 'false'. "ignoreCase" : true } | This evaluator evaluates the 'Not equals' condition. It evaluates if the value in the specified field is not equal to the value provided within the condition or not. |
NotGreaterthanEvaluator | { "id" : "notGreaterthan", "field" : "The field to be validated", "value" : "The value to be compared with", "type" : "number date" // configuration for datatype } | This class evaluates the 'Not greaterthan' condition. It evaluates if the value in the specified field is not greater than the value provided within the condition or not. It enables you to select the data type as number or date as well. |
NotInEvaluator | { "id" : "notIn", "field" : "The field to be validated", "values" : ["The value to be compared with", "Another value to be compared with"], // Optional configuration to indicate whether // the comparison should happen in a case // insensitive manner. By default is 'false'. "ignoreCase" : true } | This does a "Not In" evaluation. This converts the field data to a string representation and does the 'Not in' check. It evaluates if the field value is not available in the user defined (comma separated) value provided within the validation JSON or condition. |
NotLesserthanEvaluator | { "id" : "notLesserthan", "field" : "The field to be validated", "value" : "The value to be compared with", "type" : "number date" // configuration for datatype } | This class evaluates the 'Not lesserthan' condition. It evaluates if the value in the specified field is not lesser than the value provided within the condition or not. It enables you to select the data type as number or date as well. |
NotNullEvaluator | { "id" : "isNotNull", "field" : "The field to be validated" } | This class evaluates the 'is Not Null' condition. The value within the specified field should not be null to satisfy this condition. |
NullEvaluator | { "id" : "isNull", "field" : "The field to be validated", //Provide true if an empty value for this //field should be treated as this field //being null. "treatEmptyAsNull" : true } | This class evaluates the 'is Null' condition. The value within the specified field should be null to satisfy this condition. |
OrEvaluator | { "id" : "or", "conditions" : [{ //Provide the spec for an evaluation condition }, { //Provide the spec for an evaluation condition }] } | This is used to evaluate an 'Or' condition. It evaluates if at least one of the evaluators within the conditions are satisfied or not. |
RangeEvaluator | { "id" : "range", "field" : "The field to be validated", "valueFrom" : "The From value to be compared with" "valueTo" : "The To value to be compared with" "type" : "number date" // configuration for datatype } | This evaluator evaluates a 'between' condition. It evaluates if the value within the specified field is within the value range or not. It enables you to select the data type as number or date as well. |
StartsWithEvaluator | { "id" : "startsWith", "field" : "The field to be validated", //The value that should be used to //validate this condition. "value" : "" } | This does a 'Starts With' evaluation. This is applicable only for a String field. It evaluates if the value within the specified field starts with the value provided in the condition or not. |
Refer Custom Validation for more information on custom validating the fields in a request.