Checking values of multiple properties of a JSON output

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:

That is four questions in one. Perhaps start with one at at time.

The first point I would make is that as soon as you parse the response using pm.response.json() you are no longer working with JSON but a JavaScript object so learning basic JavaScript and how to work with objects and arrays will be helpful. (The WC3 schools is a good place to start).

When you post code, can you please use the Preformatted text option in the editor so everything isnā€™t aligned to the left (which makes it hard to read).

Lets start with the first question and go from there.

pm.expect(ā€˜Active)ā€™).to.be.oneOf(ā€˜courseDescriptionā€™));

Apart from the two extra ā€œ)ā€, youā€™ve wrapped the courseDescription in quotes, so its reading this as a string. Remove the quotes. At the moment, its just comparing the word ā€œactiveā€ with the word ā€œcourseDescriptionā€ not the variables of those names. OneOf needs an array so its failing at that point. (It will also fail because the variable ā€œactiveā€ doesnā€™t appear to be set anywhere in your code.

Your response will produce an array of JavaScript objects\records when its parsed. Which record do you want to assert against? You seem to have multiple students.

Why is one record showing ā€œstatusDescriptionā€ but the other is showing ā€œcourseDescriptionā€. Is this just a typo?

let myVariable = "Pass";    
let expectedResult = ["Pass", "Fail"];
    
pm.test("Pass or Fail", () => {
    pm.expect(myVariable).to.be.oneOf(expectedResult);
});

I would recommend going through the Postman training if you havenā€™t done so yet.

Postman Galaxy Training | Postman API Network

Run through the ā€œAPIs 101 Trainingā€, then the ā€œTesting and Automation Trainingā€ course.

Your code for checking dates is just wrong. Please Google ā€œjavascript momentā€ and you will see the correct format for using this library. You can also search this forum for examples. Try this first and then post that as a separate question and you more more likely to get a response.