Split columns into items

Hey @RomainMaltrud,

that json body is kind of strage. Espacially the way the arrays are defined. Thatswhy I think it is the best to use the code node to achieve what you want.

I created some testdata which looks like your provided one.

This code node parses your data to entries like this:

{
 "year": "2017",
 "ratios": [
  {
    "id": 1
  },
  {
    "id": 2
  }
 ]
}

This is the Code:

const returnList = [];
for (const item of $input.all()) {

  const years = Object.keys(item.json);

  

  returnList.push(years.map(year => {
   const ratios = item.json[year][0].ratios;
    return {
      'year': year,
      'ratios': ratios
    }
  }))

  item.json.test = returnList
}

return returnList[0];

If I copied your json data correctly, this code should just work plug and play.

Cheers.

3 Likes