# Websdk.serialize: can the jsonitem be a multidimensionnal array?

**URL:** <https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113>\
**Category:** Web SDK\
**Created:** [October 15, 2021, 4:34pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113 "2021-10-15T16:34:58Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 15, 2021, 4:34pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/1 "2021-10-15T16:34:58Z")

</div>

I’m trying to send a jsonitem to the browser, and it contains a multidimensionnal array  
it seems that a single array is ok, but the multidimensionnal array does not go to the browser side…

is it a bug or a feature ?  
should I fill a bug report ?

thanks.  
@Greg_O_Lone @Anthony_G_Cyphers

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 15, 2021, 4:47pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/2 "2021-10-15T16:47:31Z")

</div>

if so, can I send the multidim array as a webfile to the browser ?  
how to do this ?

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 15, 2021, 9:21pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/3 "2021-10-15T21:21:39Z")

</div>

Here is the JSON standard. It enables vectors (one dim) but not matrices (mult dim).

> **[JavaScript object basics - Learn web development | MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics)**
>
> Congratulations, you've reached the end of our first JS objects article — you should now have a good idea of how to work with objects in JavaScript — including creating your own simple objects. You should also appreciate that objects are very useful...

You probably need to build a vector of vectors (to make 2 dims), or a vector of vector of vectors to make it 3 dims.

A 2d is like “[[1,2],[3,4]]”

And you can build one as

```auto
Var js as new JSONItem("[]")

js.Add( Array(1, 2) )
js.Add( Array(2, 3) )

```

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 15, 2021, 9:35pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/4 "2021-10-15T21:35:39Z")

</div>

it’s an array of rows, containing an array of cells. so it’s a vector as you describe it  
and in the browser debugger, it does not come through.  
I store it in the serialize event “js” class, it does not arrive in the updateControl event in the browser.

if I send a one dimension json array, it arrives into the updateControl event, but not with 2 dims.

```auto
Var jsDatas As New JSONItem
Try
  Var rs As RowSet = mDatabase.selectSQL( sqlCode.ToUTF8)
  
  While Not rs.AfterLastRow
    Dim jsRow As New JSONItem
    jsRow.Add rs.Column( pk).IntegerValue
    
    For i As Integer=1 To rs.ColumnCount-1
      jsRow.Add rs.ColumnAt( i).stringValue.toUTF8
    Next i
    
    jsDatas.Add jsRow
    rs.MoveToNextRow
  Wend
  rs.Close
Catch ex As DatabaseException
  Alerte "VNSWebSDKTable.Serialize exception: "+Str(ex.ErrorNumber), ex.Message
End Try

js.Value("dataJson") = jsDatas

```

jsDatas contains good values (verified using xojo debugger)  
js contains good json values  
js in the browser updateControl event contains all js items except the jsDatas…

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 15, 2021, 11:31pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/5 "2021-10-15T23:31:40Z")

</div>

Try something like this

```auto
Var jsDatas As New JSONItem("[]") // Set as array

Try
  
  Var rs As RowSet = mDatabase.selectSQL( sqlCode.ToUTF8)
  
  While Not rs.AfterLastRow
    
    Dim jsRow() As Variant
    
    jsRow.Add rs.Column( pk ).IntegerValue
    
    For i As Integer=1 To rs.ColumnCount-1
      jsRow.Add rs.ColumnAt( i ).stringValue.toUTF8
    Next i
    
    jsDatas.Add jsRow
    rs.MoveToNextRow
    
  Wend
  
  rs.Close
  
Catch ex As DatabaseException
  Alerte "VNSWebSDKTable.Serialize exception: "+Str(ex.ErrorNumber), ex.Message
End Try

js.Value("dataJson") = jsDatas

```

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [October 16, 2021, 12:12am UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/6 "2021-10-16T00:12:28Z")

</div>

What do you expect the browser to do with it? Or have you coded that end yourself?

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 16, 2021, 6:50am UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/7 "2021-10-16T06:50:31Z")

</div>

yes I coded it that way, so that I can transfert it to the javascript side and dispatch it there.  
(fill a bootstrap table with it)

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 16, 2021, 3:04pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/8 "2021-10-16T15:04:46Z")

</div>

thanks for this but it still does not get the dataJson to the browser…  
 ![Capture d’écran 2021-10-16 à 17.03.52](https://forum.xojo.com/uploads/default/original/2X/7/760286bd46c69128432dc8f88006e9c4d997aeb7.png)

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 16, 2021, 3:26pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/9 "2021-10-16T15:26:55Z")

</div>

How are you sending it to the browser? Maybe you have some flaw in that part of the code.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 16, 2021, 4:08pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/10 "2021-10-16T16:08:47Z")

</div>

Put this in a web button pressed event. As you can see, it reaches the browser:

```auto
Var json as new JSONItem("[]")

json.Add( Array(1, 2) )
json.Add( Array(3, 4) )

// “[[1, 2] , [3, 4] ]”

// Send it to the browser as a string into a document property called jsData
Me.ExecuteJavaScript("document.jsData='" + json.ToString + "';")

// Let's see if such string reached there
Me.ExecuteJavaScript("alert('It\'s here! : '+document.jsData);")

```

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 16, 2021, 4:52pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/11 "2021-10-16T16:52:12Z")

</div>

it is for a websdk control. I don’t send it using executejavascript  
but with the serialize event of a websdkcontrol.

I will try to send it in a different way.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 16, 2021, 5:32pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/12 "2021-10-16T17:32:57Z")

</div>

> [@Jean-Yves\_Pochez](#):
>
> serialize event of a websdkcontrol.

Can you point out the docs about it? Can’t find it on the docs site.

[https://documentation.xojo.com/index.php?search=serialize](https://documentation.xojo.com/index.php?search=serialize)

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 16, 2021, 5:37pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/13 "2021-10-16T17:37:27Z")

</div>

in the Extra/WebSDK of Xojo folder.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 16, 2021, 5:51pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/14 "2021-10-16T17:51:47Z")

</div>

Sad not being in the searchable docs, same for plugin docs.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 16, 2021, 6:51pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/15 "2021-10-16T18:51:03Z")

</div>

on the good side, it is a quite sparse documentation…

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [October 16, 2021, 7:22pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/16 "2021-10-16T19:22:16Z")

</div>

So it probably means it lacks a bit of reorganization and maybe a separated domain concentrating all the related material? Like:

[documentation.xojo.com](http://documentation.xojo.com)  
[pluginsdk.documentation.xojo.com](http://pluginsdk.documentation.xojo.com)  
[websdk.documentation.xojo.com](http://websdk.documentation.xojo.com)

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 16, 2021, 9:13pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/17 "2021-10-16T21:13:08Z")

</div>

if I comment the 3 lines below from my first post, the json gets to the browser !!!

> [@Jean-Yves\_Pochez](#):
>
> ```auto
> For i As Integer=1 To rs.ColumnCount-1
> jsRow.Add rs.ColumnAt( i).stringValue.toUTF8
> Next i
> 
> ```

and so a 2 dims array seems to be valid for a websdkcontrol.serialize …

anyway I don’t understand what’s wrong with these 3 lines !

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 16, 2021, 9:26pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/18 "2021-10-16T21:26:14Z")

</div>

problem lies in :  
`jsRow.Add rs.ColumnAt( i).stringValue.toUTF8`

if I change to :

```auto
jsRow.Add "col"+str(i)

```

then it works.  
removing toUTF8 does not remove the problem.  
changing ColumnAt with Column does not remove the problem too.

_“the truth is elsewhere”_

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [October 16, 2021, 9:46pm UTC](https://forum.xojo.com/t/websdk-serialize-can-the-jsonitem-be-a-multidimensionnal-array/66113/19 "2021-10-16T21:46:19Z")

</div>

_FINALLY_ found it !  
I had to filter for special characters before storing it into the JSONItem  
changed ’ to ’  
changed " to ".  
changed EndofLine to   
  
or your json does not go to the browser !
