JSONEncode Module

Here, just use HttpService?
game:GetService(“HttpService”):JSONEncode(TableHere), or Decode also works. This works on both the client and the server! Very good for storing Tables!

1 Like

Can you please post what you were trying to encode?

1 Like

Yes that would work, but i’m trying to get the source code of JSONEncode or something like it as a module script or script.

What were you trying to convert? It’s most definitely an error with your input.

Ah! MB, sorry. I misunderstood. May be somewhere on devforum, or the internet!

It is not, actually. I am obfuscating for privacy and reasons of my own. Unobfuscated it works perfectly fine. Its suppose to send a embed to discord showing bans, kicks, and other logs of the user/s. If I could have the source code, I could figure out what went wrong and fix it.

I don’t understand what you mean. How would having the source code of a core function help you fix your discord bugs? You are using it incorrectly for it to error.

Search up “loadstring” in the toolbox and you will find a module script with the source code of the function in it. It would help me as I could see whats going wrong without just calling the function and guessing.

  1. The core functions’ source is not publicly available, nor is anyone legally allowed to read or use it other than the owners of the code.
  2. You still have not explained what you are doing with the JSONEncode function to trigger this error. Obviously, you are passing some kind of input into the function or you would get no output. What are you passing into the function?
2 Likes

I have explained it. I am encoding a embed to send to discord. It works when not obfuscated, but when obfuscated it breaks. I have no clue why this is happening and can’t just print it. I hope this answers your questions.

1 Like

Can you send the raw code you are using in this scenario?

Ex.

game:GetService("HttpService"):JSONEncode({a = 'b'})
local data = 
		{
			["embeds"] = {{
				["title"] = "**Logs**",
				["description"] = "DO NOT SHARE",
				["color"] = tonumber(0x006B8D),
				["author"] = {
					["name"] = Player.Name,
					["url"] = PlayerLink,
					["icon_url"] = "https://cdn.discordapp.com/attachments/914885865757610045/917158913135226910/Png_2.png",
				},
				["fields"] = {
					{
						["name"] = "**Game:**",
						["value"] = ""..GameLink.."\n https://www.roblox.com/games/"..game.PlaceId.."",
						["inline"] = false,
					},
					{
						["name"] = "**#Kicks:**",
						["value"] = KickCount,
						["inline"] = false
					},
					{
						["name"] = "**Bans:**",
						["value"] = BanCount,
						["inline"] = false
					}
				}
			}}
		}
	
	local EncodedData = HttpService:JSONEncode(data)
	HttpService:PostAsync(Webhook, EncodedData) 

I tested this out with some placeholder strings in place of the variables, and it worked just fine. If I had to guess, you’re accidentally encoding an instance.

Putting some example values in returns this, which is perfectly valid:

{
	"embeds": [
		{
			"fields": [
				{
					"value": "\n https://www.roblox.com/games/7209414897",
					"name": "**Game:**",
					"inline": false
				},
				{
					"value": 3,
					"name": "**#Kicks:**",
					"inline": false
				},
				{
					"value": 1,
					"name": "**Bans:**",
					"inline": false
				}
			],
			"description": "DO NOT SHARE",
			"title": "**Logs**",
			"color": 27533,
			"author": {
				"icon_url": "https://cdn.discordapp.com/attachments/914885865757610045/917158913135226910/Png_2.png",
				"name": "Name",
				"url": "Link"
			}
		}
	]
}

This is not JSONEncode’s error.

I am going off of this tutorial. Webhook's and their Embeds
It still works and i’m pretty sure your example and mine both work. I will still test this.

What do you mean by that? Could you add onto it also? Thanks!

You want to refer to the latest documentation for the most accurate info.

This is the code I used:

local HttpService = game:GetService("HttpService")
local data = 
	{
		["embeds"] = {{
			["title"] = "**Logs**",
			["description"] = "DO NOT SHARE",
			["color"] = tonumber(0x006B8D),
			["author"] = {
				["name"] = "trolling",
				["url"] = "gaming",
				["icon_url"] = "https://cdn.discordapp.com/attachments/914885865757610045/917158913135226910/Png_2.png",
			},
			["fields"] = {
				{
					["name"] = "**Game:**",
					["value"] = "".."gaming".."\n https://www.roblox.com/games/"..game.PlaceId.."",
					["inline"] = false,
				},
				{
					["name"] = "**#Kicks:**",
					["value"] = "gaming",
					["inline"] = false,
				},
				{
					["name"] = "**Bans:**",
					["value"] = "gaming",
					["inline"] = false
				}
			}
		}}
	}

local EncodedData = HttpService:JSONEncode(data)
print(EncodedData)

There were no errors, and the string that was printed out looked just fine.

Yes, but when obfuscated it gives an error. I have another script the same as this one but when obfuscated works. It says “Couldn’t convert to json.” So something is wrong with my code, but I just don’t know what.

I got the solution!
All I had to do was wrap the function with the embed in a pcall.
Simple things sometimes work, thank you all for your responses. :slight_smile:

1 Like