Variable & nested json in a table

Hello,
I haven't seen a post that covers this, but if there is one please let me know. I am getting json data representing cash flows that I would like to put into a table:
[
{
"COA": "Market Value",
"Value": {
"2020": "21,798,388",
"2021": "21,949,466",
"2022": "22,103,758",
"2023": "22,257,074",
"2024": "22,387,440",
"2025": "22,491,416",
"2026": "22,591,142",
"2027": "22,693,330",
"2028": "22,797,971",
"2029": "22,905,059",
"2030": "23,014,587",
"2031": "23,126,550",
"2032": "23,240,944",
"2033": "23,357,765",
"2034": "23,477,013",
"2035": "0",
}
},
{
"COA": "Total ERV",
"Value": {
"2020": "0",
"2021": "1,089,919",
"2022": "1,108,448",
"2023": "1,127,292",
"2024": "1,146,239",
"2025": "1,164,147",
"2026": "1,180,799",
"2027": "1,197,331",
"2028": "1,214,093",
"2029": "1,231,090",
"2030": "1,248,326",
"2031": "1,265,802",
"2032": "1,283,524",
"2033": "1,301,493",
"2034": "1,319,714",
"2035": "1,338,190",
}
},
]

This is a small example, here there are only two items, Market value and Total ERV, but the actual response has many more. I would like these items to be in the left most column, with the yearly value following. Also, this data goes from 2020 until 2035, but that is variable as well.

You're probably going to have to use a transformer to structure the data as you need it...
For example, you might need to structure it in a way so that Market Value is one column and Total ERV is another
then on the left most column would be Year; like the following?

Year - Market - ERV
2020 - 21,798,388 - 0
2021 - 21,949,466 - 1,089,919

1 Like

So what would that look like? I'm terrible with JS so any help would be appreciated :slight_smile:

var final = [];
for (k in data){
  var temp = [];
  temp["0"] = data[k].COA
  for (k2 in data[k].Value){
    if (k2.length > 4) break;
    temp[k2] = data[k].Value[k2]
  }
  final[k] = temp
}
return final
1 Like