T
TanStack4y ago
ratty-blush

How to convert a complex json response?

I use vue-query to get a very complex json from an endpoint. The {data} received is an array of complicated objects containing other objects and array of objects. The data is a reactive object. I need to transform this complicated object into completely different format so that I can show it in a tree format. This tree format data also needs to be reactive. Do I need to convert my reactive response to a plain JSON, do my transformation and then convert it back into a reactive format? What's the best strategy to do this?
4 Replies
helpful-purple
helpful-purple4y ago
Hi. You can use select: (data)=>... option to transform your response
ratty-blush
ratty-blushOP4y ago
Can you be a bit more specific, where is select: , is it a vue-query thing?
helpful-purple
helpful-purple4y ago
Migrating to React Query 3 | TanStack Query Docs
Previous versions of React Query were awesome and brought some amazing new features, more magic, and an overall better experience to the library. They also brought on massive adoption and likewise a lot of refining fire (issues/contributions) to the library and brought to light a few things that needed more polish to make the library even bette...
ratty-blush
ratty-blushOP4y ago
Thanks, Max. Much appreciated Worked like a charm
useQuery(["sats"], getSats, {
select: convertSats
});
useQuery(["sats"], getSats, {
select: convertSats
});

Did you find this page helpful?