Is there a way to convert this json table to luau and vice versa?
This is my json table.
{
"weakroblox35": {
"level": 29
}
}
but when I use a luau table and encode it to json it looks like this.
this is what I used.
HttpService:JSONEncode({ weakroblox35 = "level: 29" })
mc3334
(mc3334)
#2
JSONEncode accepts 1 argument - the JSON table as a string. Make sure the table you provide to JSONEncode is a string.
Yeah I tried and figured, but is there a way to fetch the json table from the api and use it as a body in RequestAsync
to prevent overwriting?
This is wrong. JSONDecode is the one that requires the JSON string, as it is decoding said string in to a Roblox table.
I tried doing it that but my json table turns out like this.
local HttpService = game:GetService("HttpService")
local function get()
local response = HttpService:RequestAsync({
Url = "jsonbinthing",
Method = "GET",
Headers = {
["X-Master-Key"] = "key",
["X-BIN-META"] = "false"
},
})
print(response.Body)
return response.Body
end
local function request()
local body = HttpService:JSONDecode(get())
print(body)
local response = HttpService:RequestAsync({
Url = "jsonbinthing",
Method = "PUT",
Headers = {
["Content-Type"] = "application/json",
["X-Master-Key"] = "key"
},
Body = HttpService:JSONEncode(table.pack({testvalue = {level = 43} }, body)),
})
if response.Success then
print("Status code:", response.StatusCode, response.StatusMessage)
print("Response body:\n", response.Body)
else
print("The request failed:", response.StatusCode, response.StatusMessage)
end
end
local success, message = pcall(request)
if not success then
print("Http Request failed:", message)
end
What Iām basically trying to do is, version the json.
wf_sh
(foobarbazqux)
#6
local HtppService = game:GetService("HttpService")
print(HtppService:JSONDecode("{\"weakroblox35\":{\"level\":29}}"))
Output:
16:55:08.841 ā¼ {
["weakroblox35"] = ā¼ {
["level"] = 29
}
} - Server - Script:2
local HtppService = game:GetService("HttpService")
print(HtppService:JSONEncode({
weakroblox35 = {
level = 29
}
}))
Output:
16:57:16.454 {"weakroblox35":{"level":29}} - Server - Script:2
1 Like
system
(system)
Closed
#7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.