CountTargetsData
serves as an interface for parsing JSON data with multiple levels of nesting, as illustrated below.
interface CountTargetsData {
data: {
[state: string]: {
[date: string]: {
[index: string]: { [id: string]: { [targets: string]: number } },
},
},
};
}
const parseCounters = useCallback(
async (responseDeploymentData: CountTargetsData) => {
//WANT TO PARSE ID AND TARGETS HERE
}
);
With the complex nested structure, how can I utilize the forEach()
method to extract the id
and targets
values for each entry in CountTargetsData
?
Sample Data:
"stateA": {
"2016-06-03": [
{
"1200": {
"count_targets": 1,
"count_targets_excluded": 0,
"count_targets_pending": 0,
"count_targets_in_progress": 0,
"count_targets_completed": 0,
"count_targets_failed": 1
}
}
],
"2016-06-07": [
{
"1455": {
"count_targets": 1,
"count_targets_excluded": 0,
"count_targets_pending": 0,
"count_targets_in_progress": 0,
"count_targets_completed": 1,
"count_targets_failed": 0
}
}
]
}
}