"dynaModel": [
{
"map": {
"UNIT/SUBUNIT": "EAS",
"SUBUNIT/ISU/GEO": "Africa",
"'APR-16'_REVENUEUSD-$": "$805,298",
"'APR-16'_COSTUSD-$": "$701,026",
"'APR-16'_GMINR-RSUSD-$": 12.95,
"'Total'_REVENUEUSD-$": "$805,298",
"'Total'_COSTUSD-$": "$701,026",
"'Total'_GMINR-RSUSD-$": 12.95
}
},
{
"map": {
"UNIT/SUBUNIT": "fgdfg",
"SUBUNIT/ISU/GEO": "dfgdfg",
"'APR-16'_REVENUEUSD-$": "$58,",
"'APR-16'_COSTUSD-$": "$32,",
"'APR-16'_GMINR-RSUSD-$": 43.98,
"'Total'_REVENUEUSD-$": "$58,",
"'Total'_COSTUSD-$": "$32,",
"'Total'_GMINR-RSUSD-$": 43
}
},
.... .....
How to convert it into the following below format using angular 2
output= [
{
"UNIT/SUBUNIT": "hjgh",
"SUBUNIT/ISU/GEO": "ghjg",
"'APR-16'_REVENUEUSD-$": "$805",
"'APR-16'_COSTUSD-$": "$70",
"'APR-16'_GMINR-RSUSD-$": 12.95,
"'Total'_REVENUEUSD-$": "$80",
"'Total'_COSTUSD-$": "$701",
"'Total'_GMINR-RSUSD-$": 12
},
{
"UNIT/SUBUNIT": "jjghjhj",
"SUBUNIT/ISU/GEO": "hjgh",
"'APR-16'_REVENUEUSD-$": "$58,",
"'APR-16'_COSTUSD-$": "$32,",
"'APR-16'_GMINR-RSUSD-$": 43.98,
"'Total'_REVENUEUSD-$": "$58,0",
"'Total'_COSTUSD-$": "$32,",
"'Total'_GMINR-RSUSD-$": 43.98
},
.. .. ..
];
I am recently tried as follows I extract key value pair from the first json file using following code and then push each pair in the jsonObject array.
jsonObject = [];
for(let isugeo of this.responseStatus.dynaModel){
for( let isugeomap of this.generateArray(isugeo.map)){
this.jsonObject.push(isugeomap.key+':'+"'" +isugeomap.value+"'");
} console.log('Request Completed' +
JSON.stringify(this.jsonObject));
};
generateArray(responseStatus){
return Object.keys(responseStatus).map((key) => { return {key:key, value:responseStatus[key]}});
}
but it doesn't give me the correct format any help how i will proceed