How / can I print out all slots / keys / values for a table?

Hello

If I’ve built or received a basic table in my squirrel code, is there any way to print out or get all the slots / keys / values in that table?

Thank you,
Dave

OK, to answer my own question partly, on the agent at least, you can run
http.jsonencode(mytable)

to get a string / JSON representation of the table.

On the device you can try:

`
foreach(key,value in myTable)
  server.log("key="+key+" value="+value)
`

Note: this only works if the values in your table are (integer, float, boolean, string). If you have nested arrays or tables as values, you’ll need to either:

  • send the table to the agent to be encoded as JSON
  • include a squirrel json encoder in your device code
  • write a recursive version of the foreach statement above

It’s (probably) not complete, but: https://gist.github.com/rlipscombe/b7008ba42bc5cec90a09dda8199d010c