Hi there! I’m trying to locate an object in the JSON response that has specific properties for two nested objects.
Here’s a snippet of the response
{
"data": [
{
"type": "dailyLessonAssignment",
"id": "535",
"attributes": {
"userId": 212671,
"date": "2021-05-08",
"lessonAssignmentsMetadata": [
{
"lId": 2302126,
"status": 0,
"seq": 15
},
{
"lId": 2302120,
"status": 0,
"seq": 16
},
{
"lId": 2302124,
"status": 0,
"seq": 17
}
]
},
I am able to locate the object by using the find command for 1 nested object, date:
const jsonData = pm.response.json();
const date = jsonData.data.find(u => u.attributes.date === "2021-05-08");
console.log(date);
But I’d like to locate the object by date and userId. (The response can have multiple users with the same date.)
I’ve tried the following but it returned undefined:
const date2 = _.find(jsonData.data.attributes, {
"userId": 212671,
"date": "2021-05-08"
});
console.log(date2);
Appreciate your help!