Unable to access nested json from mysql query

I've got a similar n00b question to (n00b) JSON response isn't recognized as data (?)

Here's a sample of the data in question below:


I've tried {{ data.results }} and many similar combinations to no avail, when I type data. and attempt tab completion, retool returns hints to reference each character in the string associated with each value.

Thanks in advance!

Hi there, It looks like the data is nested under the “results” key, which causes the raw JSON files to return in your table. The table components expects an array of objects or object of arrays. Since this data is nested, it needs to be converted to either one of these options. To have the table display properly, you can use a JS map function to unnest this data into an array of objects. Can you try using this code snippet in the tables data input?

{{ searchEmailByUserId.data.map(row=>row.results) }} Let us know if this doesn’t work!

Thanks @grace, unfortunately no luck…

Would you be able to share a screenshot of what your searchEmailByUserId.data property looks like expanded out in the left panel of the editor (opened in the top middle of the screen)? Having the error of “.map is not a function” makes me think that it isn’t an array currently

@alex-w that sounds logical to me, see below:

@alex-w hate to nag but does the screenshot help?

It does! It looks like these are all coming in inside of data.providerResponse as strings:

If you would always want to parse the return this way, I would recommend adding something like this as the Query’s transformer:
return data.providerResponse.map(row=>JSON.parse(row).results)
1 Like

This did the trick, thank you @alex-w

1 Like