How can I return a two dimensional array?

In my GraphQL Schema, I have a field (we can call it Cards) with two dimensional arrays.
For example, a Cards value of [[1, 2, 3], [5, 6], [], [9,10,13,14]] means highlight cards 1, 2 and 3 from the first deck, highlight cards 5 and 6 from the second deck, don’t highlight any cards in the third deck and highlight cards 9, 10, 13 and 14 in the final deck.
For this example, Retool would currently display “1,2,3,5,6,9,10,13,14” (or maybe “1,2,3,5,6,9,10,13,14”, I’m not sure how it would handle the empty array).
With this format, we can’t tell which numbers belong to which subarray and we can’t properly edit the Card field.
Can you help create a .js function that can return a two dimensional array, instead of a string of numbers, as retool is doing now? Any help would be amazing!


I’m not sure I understand. Does Retool actually flatten the two-dimensional array from your GraphQL response, and you’re asking how to get it back? Or if not, what does the response from the GraphQL query look like, and where (which component) do you want to use it?

Hello! When you put a JSON object in a Text component, we call .toString() on it. In JS, that is:

[[1, 2, 3], [5, 6], [], [9,10,13,14]].toString() "1,2,3,5,6,,9,10,13,14"

So instead, you want to write this in your Text component:

<pre>{{ JSON.stringify([[1, 2, 3], [5, 6], [], [9,10,13,14]])}}</pre>

Hi David, Thanks for the quick response! That worked really well but GraphQL is complaining that it is expecting an array of Int’s and I have an array of strings. I’ve been reading up on json5 where I found the stringify function. Do you use json5 in retool to help with some of the javascript transforms?
Since Retool is a tool used by developers, it would probably be useful to provide developers with some context in your docs around which javascript libraries you leverage. I’m not advocating to reveal anything proprietary but it could be helpful to know which version of javascript and which util libraries that might work out of the box.

I’m going to continue to try and figure this out on my end…

I couldn’t figure out an elegant way to solve this so I switched to the JSON Editor control. It might be ugly, but it did the trick! :slight_smile: