Below is JSON body returned from an API call. I'm using Postman and want to create a test using JavaScript to count the number of objects ("id"s) in the JSON returned. Something like tests["Only 1 login"] = objects=1 is a PASS, else Fail.
[
{
"id": 243,
"user_id": 76,
"account_id": 1,
"unique_id": "12345",
"special_user_id": null,
},
{
"id": 244,
"user_id": 84,
"account_id": 1,
"unique_id": "123456",
"special_user_id": "staff_123456",
}
]
tests["Only 1 login"]or how it connects toPASSandFAIL. Do you mean you want to see if there is one element in the array? Is the array already parsed into a JS object, or are you stuck on how to do that (hint:JSON.parse). For getting the number of items in the array (usually known as its "length"), see MDN.