Hi there,
I am struggling with a JSON result that I get from an API: it gives me an output with several columns.
Here is a screenshot :
What I am trying to achieve, is to get ratios (42 items) per year.
Here is another screenshot :
Is there any solution ?
Thanks a lot!
Romain
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
Wow @nico-kow , thank you so much ! It worked PERFECTLY !
Note for future research, if it might help, data came from Pappers’ API : https://www.pappers.fr/api/documentation#operation/comptes-annuels
1 Like
system
Closed
November 13, 2023, 11:15pm
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.