Stop being the product.
Become the owner.
or
sign uplog in

Do you prefer flattening API responses or keeping nested…

Do you prefer flattening API responses or keeping nested structures on the frontend?

Hey everyone,



I’ve been working on a small project where I consume structured player data (ratings, attributes, etc.) from an API.



One design choice I’m unsure about is how to handle nested data on the frontend.



For example, the API returns grouped stats like:



\- speed

\- shooting

\- passing

\- dribbling

\- defense

\- physical



So in JS I end up doing things like:



const player = await getPlayer(2021);



console.log(player.shooting.score);

console.log(player.shooting.stats.finishing);



This works well for organization, but sometimes feels a bit verbose when building UI components.



I’ve seen other approaches where people flatten everything on the frontend for easier access.



Curious what you prefer in practice:



\- Keep nested structures and work with them directly?

\- Or transform/flatten responses on the frontend?



And if you flatten, do you do it manually or with some utility layer?
#dev #technology #js #programming
earnings
4,000 mlx total
$0  total
engagement
5 views
0 reactions

0 comments