I have couple of issues as below. I tried couple of times but it is not working. I would appreciate your help and please also recommend the best way to get rid of the errors.
JSON response
[
{
āstudentNameā: āMike Tuckerā,
āstartDateā: ā2011-08-08 12:12:16.257ā,
āisActiveā: ātrueā,
āstatusDescriptionā: āPassā,
āstudentIdā: ā39524ā
},
{
āstudentNameā: āJames Brownā,
āstartDateā: ā2012-11-06 12:15:12.72ā,
āisActiveā: ātrueā,
ācourseDescriptionā: āFailā,
āstudentIdā: ā52412ā
}
]
I would like to know the ācourseDescriptionā value is either āPassā or āFailā from the above json output
I tried the following script but it is not working
var jsonData = pm.response.json();
var courseDescription =[āPassā,āFailā];
pm.test(ācourseDescriptionā is working as expectedā,()=>{
pm.expect(āActive)ā).to.be.oneOf(ācourseDescriptionā));
});
Error : AssertionError: expected ācourseDescriptionā to be an array
I would like to know the date format above output is YYYY-MM-DD with the script below for all json objects
I tried the script below and it is not working
var josnData= pm.response.json();
var moment = require(āmomentā);
var startDate= āYYYY-MM-DDā;
pm.test(āChecking date formatā, () =>
{
pm.expect(jsonData.data.startDate).to.include(moment).format(startDate)});
Error : ReferenceError: jsonData is not defined
I would like to check the studentID is an integer for all the json objects and length of it .i.e in this case stuedntID length is 5 digit. I tried the following script ,please let me know the piece I am missing
AssertionError: expected undefined to be a number
var data = pm.response.json();
pm.test(āstudentID is integer and be below 6 digitā, function () {
pm.expect(data.studentID).to.be.a(ānumberā);
pm.expect(data.studentID).be.below(6);
});
Error : AssertionError: expected undefined to be a number
I would like to check details of studentID # 52412 from all the json output above. I tried the script below and need your suggestions to work
var jsonData = pm.response.json();
pm.test(āstudentID 52412ā, function() {
pm.expect(jsonData).to.have.property(jsonData.data.studentID==52412ā);
});
Please also refer any good json libraries that are helpful for me to learn for future.
Iāve already tried: