In Brief:
I'm getting (
JSON schema validation failed. Array value found, but a null or an object is required
) error message on the Response Payload for a custom HTTPS Sample Request payload that I created using BeanShell PreProsser to send couple of Arrays.
STEP 1:
I'm using BeanShell PreProcessor to create and object from the data available in a CSV file (sampleGroups.csv) as below:
import java.text.*;
import java.io.*;
import java.util.*;
ArrayList stl = new ArrayList();
int count = 1;
int limit = ${__P(upcLimit,101)};
try {
File file = new File (${__P(data1, "sampleGroups.csv")});
if (!file.exists()) {
throw new Exception ("ERROR: file not found");
}
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
while(((line = bufRdr.readLine()) != null) && (count < limit))
{
stl.add(line);
count++;
}
bufRdr.close();
}
catch (Exception ex) {
IsSuccess = false;
log.error(ex.getMessage());
System.err.println(ex.getMessage());
}
catch (Throwable thex) {
System.err.println(thex.getMessage());
}
vars.putObject("groups",stl);
STEP 2:
Then added the "groups" object in the main Request Payload to make an array as below:
{
"included": {
"groups": ${groups},
"tags": ${tags}
}
}
NOTE: I used similar steps to create "tags" array with one more BeanShell Pre-Processor.
STEP 3 (REQUEST PAYLOD):
Then the Request Payload that the HTTP Sampler posts is as below:
{
"included": {
"groups": [
"CANDY, GUM & MINTS",
"TAKE HOME CANDY, GUM & MINTS",
"SEASONAL CANDY, GUM & MINTS",
"BULK CANDY/GUM/MINT -NS"
],
"tags": [
"ACME,ADAL,AIMT,AJWL,AKBA,ASHA,ASOC,AVMT,PSOC,RDAL,SACG,SDEN,SHAW,SHGN,SNCA,SPHO,SPRT,SSEA,SSPK,SWMA,VLAS,VSOC",
"ACME,ADAL,AIMT,AJWL,ASHA,ASOC,AVMT,PSOC,RDAL,SACG,SHAW,SNCA,SPRT,SSEA,SSPK,SWMA,VSOC",
"ACME,AKBA,SWMA",
"ACME,ADAL,AIMT,AJWL,AKBA,ASHA,ASOC,AVMT,PSOC,RDAL,SACG,SDEN,SHAW,SHGN,SNCA,SPHO,SPRT,SSEA,SSPK,SWMA,UNTD,VLAS,VSOC"
]
}
}
STEP 4 - RESPONSE PAYLOD (WITH ERROR):
However, I'm getting below error on the Response Payload for "groups" array and not for the "tags" array:
{"errorCode":"ISF","errorMessage":"JSON schema validation failed in 2 areas in included.groups - Array value found, but a null or an object is required"}
The only difference in these to arrays are that items within the "groups" array has special characters such as space, comma, ampersand, slash etc. Whereas, the "tags" do not have any special characters.
- POINT TO BE NOTED:
The test data contained in the sampleGroups.csv file has those special characters as per the raw data provided to me by my client. Because the data were ingested to the database as seen below, hence it has to have those characters to make like-for-like to prod data. And I need to send the Arrays with lists as it is.
sampleGroups.csv
"CANDY, GUM & MINTS"
"TAKE HOME CANDY, GUM & MINTS"
"SEASONAL CANDY, GUM & MINTS"
"BULK CANDY/GUM/MINT -NS"
sampleTags.csv
"ACME,ADAL,AIMT,AJWL,AKBA,ASHA,ASOC,AVMT,PSOC,RDAL,SACG,SDEN,SHAW,SHGN,SNCA,SPHO,SPRT,SSEA,SSPK,SWMA,VLAS,VSOC"
"ACME,ADAL,AIMT,AJWL,ASHA,ASOC,AVMT,PSOC,RDAL,SACG,SHAW,SNCA,SPRT,SSEA,SSPK,SWMA,VSOC"
"ACME,AKBA,SWMA"
"ACME,ADAL,AIMT,AJWL,AKBA,ASHA,ASOC,AVMT,PSOC,RDAL,SACG,SDEN,SHAW,SHGN,SNCA,SPHO,SPRT,SSEA,SSPK,SWMA,UNTD,VLAS,VSOC"
WHAT I TRIED:
I found 1 post which did touch the issue related to JSON Schema validation. However, it is not applicable for my issue.
Any help would be much appreciated. Thanks!