In order to achieve your goal, it seems that a recursive data structure may not be necessary for the task at hand. The key lies in traversing the data and identifying the specific information you require. Understanding which data is needed and devising a strategy to locate it poses the main challenge.
Here is a possible starting point for your endeavor:
// In case there are multiple elements within qPivotDataPages, iteration is required
// to call 'process' for each one and then merge the resulting arrays.
const data = json.qPivotDataPages[0].qLeft;
const result = process(data);
function process(input) {
const [team1, team2] = input;
const team1Results = processTeam(team1);
const team2Results = processTeam(team2);
return [...team1Results, ...team2Results];
}
function processTeam(teamData) {
const teamResults = [];
const teamName = teamData.qText;
const halfDatas = teamData.qSubNodes.filter((item) => item.qText === '1st' || item.qText === '2nd' || item.qText === 'InCia');
halfDatas.forEach((halfData) => {
const half = halfData.qText;
halfData.qSubNodes.forEach((item) => {
if (item.qText === 'MI' || item.qText === 'ME') {
teamResults.push({
team: teamName,
half: half,
type: item.qText,
});
}
});
});
return teamResults;
}