JSFiddle - React, Tailwind, and code Playground
by dougiei
JavaScript
var rec = { "ProductId": "CC#001",
"ProductUuid": "D8C2017195FD40B0BEB38A0BBB4CDB50",
"ProductInfo": {
"ShortName": "VISA BASIC CREDIT CARD FOR SB",
"Name": "VISA BASIC CREDIT CARD FOR SMALL BUSINESS",
"Desc": "Lorem ipsum dolor sit amet .....",
"BaseProductInd": true,
"CompanyUuid": "CDCD20B95D024AF9A5AD4981D68AC918",
"CompanyShortName": "Wachovia",
"ActiveDt": "2017-01-23T00:00:00.000Z",
"InactiveDt": "2020-09-20T00:00:00.000Z"
}
};
var prodKeyMap = {
"id": "ProductId",
"uuid": "ProductUuid",
"name": "ProductInfo.Name",
"desc": "ProductInfo.Desc",
"shortname": "ProductInfo.ShortName",
"companyuuid" : "ProductInfo.CompanyUuid",
"companyshortname" : "ProductInfo.CompanyShortName",
"ActiveDt" : "ProductInfo.ActiveDate",
"InactiveDt" : "ProductInfo.InactiveDt"
};
function flatten(element, keymap) {
return ({
id: element[keymap.id],
uuid: element[keymap.uuid],
shortname: element[keymap.shortname],
name: element[keymap.name]
})
}
console.clear();
console.log(rec)
console.log ("Short Name",rec["ProductInfo"]["ShortName"]);
console.log ("Short Name",rec.ProductInfo.ShortName);
console.log("map ",prodKeyMap.shortname )
console.log
console.log (flatten(rec,prodKeyMap));