Encoding JSON for a Discord webhook

Hello, I’m trying to send a Discord webhook whenever a player touches a brick. I have been testing it out so far.

I designed my webhook using an online webhook creator and have basically taken the JSON from that. I’m looking to translate it into a LUA compatible string of text that can be encoded and sent off but I am having trouble with the JSON [] character. I’m not really sure what that would ‘translate’ too?

	local data = {
							
					  embeds = [
					    {
					      description = "PureGamerGames was caught in the helicopter area...",
					      color = 16561212,
					      author = {
					        name = "Helicopters",
					        icon_url = "https://media.discordapp.net/attachments/542426219287805953/718917497578848286/unnamed.png?width=678&height=678"
					      },
					      footer = {
					        text = "SCRP • Logs for moderation purposes only"
					      },
					      thumbnail = {
					        url = "https://media.discordapp.net/attachments/354983300114415617/720329691839332442/warning_symbol_in_orange.png"
					      }
					    }
					  ],
					
					  avatar_url = "https://media.discordapp.net/attachments/542426219287805953/718917497578848286/unnamed.png?width=678&height=678"
	}

^ Currently what I have done. Roblox isn’t liking the ‘[’

{
  "embeds": [
    {
      "description": "PureGamerGames was caught in the helicopter area...",
      "color": 16561212,
      "author": {
        "name": "Helicopters",
        "icon_url": "https://media.discordapp.net/attachments/542426219287805953/718917497578848286/unnamed.png?width=678&height=678"
      },
      "footer": {
        "text": "SCRP • Logs for moderation purposes only"
      },
      "thumbnail": {
        "url": "https://media.discordapp.net/attachments/354983300114415617/720329691839332442/warning_symbol_in_orange.png"
      }
    }
  ],
  "avatar_url": "https://media.discordapp.net/attachments/542426219287805953/718917497578848286/unnamed.png?width=678&height=678"
}

^The JSON

How could I fix the already translated JSON to work? I can’t just keep it as JSON because I need to dynamically change some of the text to suit player details.

Thank you!
:slight_smile:

Have you heard of JSONEncode?

Or maybe just make the whole thing a string. You can put everything inside [[here]].

I haven’t really messed around with web stuff.

1 Like

That is what I’m doing, The top code is the variable that I am encoding but I don’t know what the Roblox equivalent for [ and ] is in JSON.

Sorry if I didn’t explain it very well.

In Lua you use curly brackets {} for both arrays and objects.

local data = {
	embeds = {
		{
			description = "PureGamerGames was caught in the helicopter area...",
			color = 16561212,
			author = {
				name = "Helicopters",
				icon_url = "https://media.discordapp.net/attachments/542426219287805953/718917497578848286/unnamed.png?width=678&height=678"
			},
			footer = {
				text = "SCRP • Logs for moderation purposes only"
			},
			thumbnail = {
				url = "https://media.discordapp.net/attachments/354983300114415617/720329691839332442/warning_symbol_in_orange.png"
			}
		}
	},			
	avatar_url = "https://media.discordapp.net/attachments/542426219287805953/718917497578848286/unnamed.png?width=678&height=678"
}

print(game:GetService("HttpService"):JSONEncode(data)) -- JSON string
4 Likes