Logic Machine Forum
Json tables - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Json tables (/showthread.php?tid=4647)



Json tables - tomnord - 14.03.2023

When communicating with API's, we often get replys with som intricate system of data in tables.
For instance, one reply would be: responce["response"][1]["more_response"],  responce["response"][2]["more_response"],  responce["response"][xx+]["more_response"].
Is there any way to just show how many "[xx]" there are in the responce table? as this is dynamic, the rest of my code is dependent of knowing this.

Thanks in advance.


RE: Json tables - admin - 14.03.2023

Use the length operator (#): https://www.lua.org/manual/5.1/manual.html#2.5.5
Or you can use ipairs to go through the whole table: https://openrb.com/docs/lua.htm#ipairs