Skip to main content

Below is sample array of JSON request. We have three groupsTypes(work,Home,Other defined in "prodVoc" field).

Below array can have any number of objects, it could be empty also. But we have to show 3 types related fields in output json.

 

Input JSON:

 

Cars[

{"prodName":"Toyota","ProjectId":11,"prodColor":"yellow","prodVoc":"other","isReq":false},

{"prodName":"Hundai","ProjectId":12,"prodColor":"Green","prodVoc":"work","isReq":false},

{"prodName":"KIA","ProjectId":13,"prodColor":"Red","prodVoc":"Home","isReq":true},

{"prodName":"Doddge","ProjectId":14,"prodColor":"White","prodVoc":"Home","isReq":false},

{"prodName":"ASKL","ProjectId":15,"prodColor":"GreenWithRed","prodVoc":"work","isReq":true},

{"prodName":"TATA","ProjectId":16,"prodColor":"GreenWithYellow","prodVoc":"work","isReq":true},

{"prodName":"Mahindra","ProjectId":17,"prodColor":"GreenWithBlue","prodVoc":"work","isReq":false}

]

 

Expecting Output JSON:

 

{

prodWorkName: "TATA", //Work data

WorkprodColor:GreenWithYellow, //Work data

prodHomeName: "KIA", //Home data

HomeprodColor: "Red", //Home data

prodOtherName: "Toyota", //Other Data

OtherprodColor: "Yellow" // Other data

}

 

Scenarios:

 

1. If all "isReq" false then take highest ProjectId and show it corresponding groupType and prodColor.

2. If any isReq true then take corresponding groupType and corresponding hightst projectId in group and show it in "prodVoc" type.

3. If all "isReq" true then take highest ProjectId and show it corresponding groupTyp and prodColor.

4. If there is no objects in the related fields should show no data. Example is no "prodVoc":"other" object , then show the value is "no Data" in output json.

5. if 2 objects value isReq : true then take the hightest projectID that is ("ProjectId":16) and populate in output json for work details.