Table to JSON Issues

I want to make a system that reads the bool values ​​in the files and sends them to the discord.

but I’m getting HTTP 400 Bad request error, I searched for the reason and saw that discord could not print in table format, but I don’t know how to print bool values ​​using \n.

local function CheckFolders(player,foldername)
	if player ~= nil then
		if foldername.Name == "Hoverboard" then
			for number,obj in pairs(foldername:GetChildren()) do
				HoverboardTable[#HoverboardTable + 1] = tostring(tostring(obj.Name).." = **"..tostring(obj.Value).."**")
			end
			return HoverboardTable
		elseif foldername.Name == "PassList" then
			for number,obj in pairs(foldername:GetChildren()) do
				PassTable[#PassTable + 1] = tostring(obj.Name).." = **"..tostring(obj.Value).."**"
			end
			return PassTable
		end
	end
end

function webhookHandler:SendMessage(player,Type,message)
	local passlist = player:WaitForChild("PassList")
	local hoverlist = player:WaitForChild("Hoverboard")
	
	local userId = player.UserId
	
	local date = os.date("!*t")
	local Data = {
		["contents"] = "",
		["embeds"] = {
			{
				["title"]= "Player information:",
				["color"] = 36096,
				["author"] =  {
					["name"]= player.Name.." joined the game!",
					["url"] = "https://www.roblox.com/users/"..userId.."/profile",
					["icon_url"] = "https://www.roblox.com/headshot-thumbnail/image?userId="..userId.."&width=420&height=420&format=png"
				},
				
				["fields"] = {
					{
						["name"] = "Level",
						["value"] = Players[player.Name]:WaitForChild("NametagSaves").Level.Value,
						["inline"] = true	
					},
					{
						["name"] = "Gamepass List",
						["value"] = CheckFolders(player,passlist),
						["inline"] = true	
					},
					{
						["name"] = "Hoverboard List",
						["value"] = CheckFolders(player,hoverlist),
						["inline"] = true	
					},
					{
						["name"] = "Radio List",
						["value"] = "none",
						["inline"] = true	
					}
				},
				
				["footer"] = {
					["text"] = date.day.."/"..date.month.."/"..date.year,
				}
			}
		}
	}
	
	if Type == "Join" then
		Data = HttpService:JSONEncode(Data)
		print(Data)
		HttpService:PostAsync(URL, Data)
	end
end

The full form after printing is like this:

{“contents”:"",“embeds”:[{“fields”:[{“value”:1940,“name”:“Level”,“inline”:true},{“value”:[[“HoverboardPass = true”,“RadioPass = true”,“VIPPass = true”,“HousePass = true”]],“name”:“Gamepass List”,“inline”:true},{“value”:[[“Cat = true”,“Tech = true”]],“name”:“Hoverboard List”,“inline”:true},{“value”:“none”,“name”:“Radio List”,“inline”:true}],“title”:“Player information:”,“footer”:{“text”:“28/5/2022”},“color”:36096,“author”:{“icon_url”:“https://www.roblox.com/headshot-thumbnail/image?userId=1677188092&width=420&height=420&format=png",“name”:"N3mes1s_Nyks joined the game!”,“url”:“https://www.roblox.com/users/1677188092/profile”}}]}

You can look it up yourself with json beautifier.

Here’s how it looks when converted to json:
image

The way it should actually be:
image

If you have any information on this subject, please do not hesitate to let me know. I’ll be sure to take an active look, thanks in advance for your help.

try to convert the table to string. Try this

local function CheckFolders(player,foldername)
	if player ~= nil then
		if foldername.Name == "Hoverboard" then
			for number,obj in pairs(foldername:GetChildren()) do
				HoverboardTable[#HoverboardTable + 1] = tostring(tostring(obj.Name).." = **"..tostring(obj.Value).."**")
			end
			return tostring(HoverboardTable)
		elseif foldername.Name == "PassList" then
			for number,obj in pairs(foldername:GetChildren()) do
				PassTable[#PassTable + 1] = tostring(obj.Name).." = **"..tostring(obj.Value).."**"
			end
			return tostring(PassTable)
		end
	end
end

unfortunately, when you connect the table, it only gives the information of the table, not the data in it.

image

ok then send the table through this function

function convertTabletoString(inputTable)
        local endResult = ""

        for i,v in pairs(inputTable)
              endResult += endResult .. v .. "\n"
        end

      return endResult
end
1 Like

this time i get an error like this:

image

wrong line of code:

function convertTabletoString(inputTable)
	local endResult = ""

	for i,v in pairs(inputTable) do
		endResult += v .. "\n" -- here line 22
	end

	return endResult
end

Try this:

function convertTabletoString(inputTable)
        local endResult = ""

        for i,v in pairs(inputTable)
              endResult = endResult .. v .. "\n"
        end

      return endResult
end
2 Likes

yes finally it worked as i wanted thank you both very much :grinning:

It will be a good solution for those who have similar errors as me. :sweat_smile:

great! I am happy I helped
:slight_smile:

char

1 Like