GenerateJSON failing with an OutOfBoundsException

I have a multi-dimensional string array (many rows, 2 columns) that along with several other data items are placed into a dictionary. So far so good. But when I try to generate JSON from the dictionary, it throws an OutOfBoundsException.

I put together a very small bit of code that illustrates the problem:

Dim dicJSON As New Xojo.Core.Dictionary
Dim txtJSON As Text

Dim arrData(4,1) As String

arrData(0,0) = "001"
arrData(0,1) = "Maryland"
arrData(1,0) = "002"
arrData(1,1) = "Texas"
arrData(2,0) = "003"
arrData(2,1) = "Florida"
arrData(3,0) = "004"
arrData(3,1) = "New York"
arrData(4,0) = "005"
arrData(4,1) = "Oregon"

dicJSON.Value("Data") = arrData

txtJSON = Xojo.Data.GenerateJSON(dicJSON)  ' This throws an "OutOfBoundsException"

System.DebugLog(txtJSON)

Is there some restriction on generating JSON that contains multi-dimensional arrays? Generating JSON from simple arrays seem to work perfectly.

I’m running Xojo 2017 Release 1.1 if that is relevant.

-Wes

There’s really no concept of a multidimensional array in JSON so what you’re seeing does not surprise me.

Now… if you had an array of auto which contained other arrays, that might work.

Maybe I’m using the wrong terminology but a quick search turned up many instances of multi-dimensional arrays in JSON.
I believe the example code I gave above should produce the following (which is valid JSON):

{
  "Data":[
    ["001","Maryland"],
    ["002","Texas"],
    ["003","Florida"],
    ["004","New York"],
    ["005","Florida"]
  ]
}

That is not a multi-dimensional array. It is an array of arrays, represented in Xojo by an Auto() array of Auto(), just as Greg described. If you were to parse that, you’d get a Dictionary with a single key, “Data”, that contains an Auto() array. Each element of that array would be another Auto() array.

Ah. I’m used to “Array of Arrays” from PHP. I’ll experiment with Greg’s suggestion and see if I can achieve the results I’m looking for.
Thanks to you both for the explanation.

Just a quick note to say that Greg’s idea of using an “array of auto which contained other arrays” worked perfectly. Thanks again guys.

The one thing I haven’t figured out is if it’s possible to refer to the elements within “a dictionary holding an array holding other arrays” without having to unpack the whole structure to get at the various elements?

My attempts so far have been unsuccessful. Unpacking takes some effort but it works. Accessing the individual elements without unpacking first would be better. Any ideas?