Json Response has data with Nested Array Columns but most of the Array columns are empty .So need to identify Records which are not null or have more than one column data

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
patientProcedures,practiceProcedures,visits are nested arrays with columns like
{
id:123
,type:‘some string’
,url :‘Some http Url’
}
But in most of my Json response they are empty .I want to filter and fetch only records which have
not null array values (patientProcedures,practiceProcedures,visits) so that i can test loading them in a database

Details (like screenshots):

I have attached Json with two records for example but my json has 25k records

{
“statusCode”: 200,
“data”: [
{
“type”: “AppointmentV1”,
“lastModified”: “2016-07-08T16:53:13.657Z”,
“duration”: 60,
“statusId”: 5,
“patientProcedures”: ,
“practiceProcedures”: ,
“visits”: ,
“id”: “7000002983226”,
“title”: “Appointment”,
“start”: “2002-08-30T14:30:00.000Z”,
“created”: “2016-04-20T05:27:41.840Z”,
“end”: “2002-08-30T15:30:00.000Z”,
“needsFollowUp”: false,
“needsPremedicate”: false,
“status”: “COMPLETED”,
“note”: “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”,
“other”: “CCAdult”,
“bookedOnline”: false,
“patient”: {
“id”: “7000001065834”,
“type”: “PatientV1”,
“url”: “TestUrl”
},
“location”: {
“id”: “7000000000260”,
“type”: “LocationV1”,
“url”: “Url1”
},
“provider”: {
“id”: “7000000000774”,
“type”: “ProviderV1”,
“url”: “Url2”
},
“operatory”: {
“id”: “7000000000550”,
“type”: “OperatoryV1”,
“url”: “Url3”
}
},
{
“type”: “AppointmentV1”,
“lastModified”: “2016-07-08T16:53:13.657Z”,
“duration”: 60,
“statusId”: 5,
“patientProcedures”: ,
“practiceProcedures”: ,
“visits”: ,
“id”: “7000002983227”,
“title”: “Appointment”,
“start”: “2002-08-02T17:30:00.000Z”,
“created”: “2016-04-20T05:27:41.840Z”,
“end”: “2002-08-02T18:30:00.000Z”,
“needsFollowUp”: false,
“needsPremedicate”: false,
“status”: “COMPLETED”,
“note”: “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”,
“other”: “CCAdult”,
“bookedOnline”: false,
“patient”: {
“id”: “7000001066365”,
“type”: “PatientV1”,
“url”: “Url4”
},
“location”: {
“id”: “7000000000260”,
“type”: “LocationV1”,
“url”: “Url5”
},
“provider”: {
“id”: “7000000000774”,
“type”: “ProviderV1”,
“url”: “Url6”
},
“operatory”: {
“id”: “7000000000550”,
“type”: “OperatoryV1”,
“url”: “Url7”
}
}
],
“meta”: {
“pagination”: {
“limit”: 2,
“offset”: 0,
“total”: 23895
}
}
}

How I found the problem:

I’ve already tried:

Please use the preformatted text option in the editor when pasting code or JSON.

It’s stops everything being aligned to the left and preserves the quotes so it can be cut and pasted properly.

Something like the following should work.

It uses the JavaScript filter function and checks the length of each array to return the results.

const response = pm.response.json();

let search = response.data.filter(function (obj) {
        return obj.patientProcedures.length > 0 && obj.practiceProcedures.length > 0 && obj.visits.length > 0
});

console.log(search);

pm.test(`search results are not empty`, () => {
    pm.expect(search).to.be.an("array").that.is.not.empty;    
});