Reputation: 21
Below is my JSON that I have fetched from the server. now I have to create a separate list based on docgroup
. Suppose there is 2 same PAN Card value for docgroup
. So I have to create a list of docgroup
which has PAN Card as value. So what really I want is, first we have to check to find the similar docgroup
value and create a list of that.
Thank you in advance.
[
{
"name": "Upload front side",
"information": "Should match PAN no. mentioned on IEC copy and self attested",
"docgroup": "PAN Card",
"status": "Active",
"requiredStatus": 0,
"stage": 1,
"type": 0,
"extension": "string",
"createdBy": 0,
"createdAt": "2021-06-08 04:46:00.822",
"lastupdatedBy": 0,
"lastUpdatedAt": "2021-06-08 04:46:00.822",
"id": 1,
"countryId": 1
},
{
"name": "Upload back side",
"information": "Should match PAN no. mentioned on IEC copy and self attested",
"docgroup": "PAN Card",
"status": "Active",
"requiredStatus": 0,
"stage": 1,
"type": 0,
"extension": "string",
"createdBy": 0,
"createdAt": "2021-06-08 04:46:00.822",
"lastupdatedBy": 0,
"lastUpdatedAt": "2021-06-08 04:46:00.822",
"id": 2,
"countryId": 1
},
{
"name": "Upload IEC copy",
"information": "Please upload IEC copy (self attested)",
"docgroup": "IEC Copy",
"status": "Active",
"requiredStatus": 0,
"stage": 1,
"type": 0,
"extension": "string",
"createdBy": 0,
"createdAt": "2021-06-08 04:46:00.822",
"lastupdatedBy": 0,
"lastUpdatedAt": "2021-06-08 04:46:00.822",
"id": 3,
"countryId": 1
},
{
"name": "Upload address proof",
"information": "Please upload latest electricity bill/ telephone bill (any 1)",
"docgroup": "Office address proof",
"status": "Active",
"requiredStatus": 0,
"stage": 1,
"type": 0,
"extension": "string",
"createdBy": 0,
"createdAt": "2021-06-08 04:46:00.822",
"lastupdatedBy": 0,
"lastUpdatedAt": "2021-06-08 04:46:00.822",
"id": 4,
"countryId": 1
}
]
Upvotes: 0
Views: 22
Reputation: 366
You can use List.where()
to group/filter lists based on some condition.
For your case check this out.
List panCardList = jsonList.where((json) => json['docgroup'] == 'PAN Card');
List otherCardList = jsonList.where((json) => json['docgroup'] != 'PAN Card');
Upvotes: 1