This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

json.encode square brackets
#1
Hello!

Is there a way to add square brackets in the result when using json.encode?

I want the following:

Code:
local var_ = json.encode({
RoomStatus = 0
)}

to look like this:

Code:
"RoomStatus":[0]

when using log(var_)
Reply
#2
Code:
json.encode({
  RoomStatus = {0}
})
Reply
#3
Thank you!

As a response from an API call, i get the following table:

Code:
API 08.03.2023 15:01:36
* table:
["NumberOfBeds"]
  * number: 0
["WeekDays"]
  * userdata: NULL
["RoomStatusAlias"]
  * userdata: NULL
["Floor"]
  * userdata: NULL
["Number"]
  * userdata: NULL

Is there a way to convert the "userdata" to a string?
Whenever I try to access it, I get the error message "attempt to index field 'Room' (a userdata value)".
Reply
#4
You don't need to convert it, it just states the data is empty (NULL). Since there's no separate NULL type in Lua so a userdata entry (json.null) is used instead.
Reply


Forum Jump: