Table to JSON Issues

Table to JSON Issues

I am having issues with my code. I wish to make a discord webhook, which worked earlier. My primary issue is trying to ignore " using backslash (\). You can review my script here:

local data = 
    {
        ["content"] = "",
        ["embeds"] = {
            ["title"] = playerN.Name,
            ["author"] = {
                ["Name"] = context.Executor.Name,
            },
            
            ["description"] = "\"".. Chat:FilterStringForBroadcast(reason, context.Executor) .."\"",
        },
    }

local newdata = HttpService:JSONEncode(data)
print(newdata)
HttpService:PostAsync(WebhookURL,newdata)
return "Success!"

JSON Data (that was printed in the output)

You can also review the encoded JSON data here:

{"embeds":{"description":"\"exploiting\"","title":"PhosilioQuinnley","author":{"Name":"PhosilioQuinnley"}},"content":""}

Error printed in Output

The error message can be found here:

Expected Outcome

You may view the expected outcome:
Screenshot 2020-07-22 at 18.38.05

I appreciate that you took the time to read this query and I’ll be interested to see what you have to make of it. :smile:

The webhook url is possibly invalid, this error occurs normally when roblox cannot access the url that you give

1 Like

It isn’t because the main issue is the description, I’m fairly sure. I’ll test it again though to make sure.

Your structure is invalid for Discord. Remember that embeds should be a list of embeds, where each embed object is a dictionary. You have it set to a dictionary when it should be a list of dictionaries. If you only want a message with a single embed, it would be a list with one dictionary in it that is the embed object.

Another thing: the Name key in the embed dictionary should not be capitalized; it should be lowercase.

local data = 
    {
        ["content"] = "",
        ["embeds"] = { -- Should be a list of dictionaries which are embed objects, not a dictionary itself
            { -- Made this into a list with a single embed
               ["title"] = playerN.Name,
                ["author"] = {
                    ["name"] = context.Executor.Name -- Should be lowercase
                },
            
                ["description"] = "\"".. Chat:FilterStringForBroadcast(reason, context.Executor) .."\""
            }
        }
    }
1 Like

400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

I was thinking of 404 Not Found, embeds is meant to be a list

1 Like

You have solved it. That was the problem all along. Thanks a lot, you have helped me and I’ll be able to apply this in the future for when I use JSON encoding again. A lot of people didn’t know how it was done, so thanks again!

1 Like