Can't parse JSON error with Pastebin

I’m trying to create a code system for my game with a pastebin. Doing so, I can easily add codes without having to open studio and shut down the game every time I add or remove a code.

Pretty much how this works is that players enter a code, the script then grabs the code title, code prize, and code value from Pastebin.

An example could be that you enter a specific code and then receives a speed boost for 30 seconds. The prize would be “Speed” and the value would be 30.

I’m not entirely sure how JSON works and I can’t figure out the reason to why my code can’t parse JSON.

Pastebin Link:

Here is the function I use when a code is entered:

local function enterCode(Code)
	local pastebinLink = HttpsService:GetAsync(CodeURL)
	if HttpsService:JSONDecode(pastebinLink) then 
		local data = HttpsService:JSONDecode(pastebinLink)  -- get's the data from one code. code name, code prize and code value
		if data[Code] then-- code is the actual code name, it finds it in the table 
			print("Code successful")

The line that doesn’t work is

if HttpsService:JSONDecode(pastebinLink) then

Not entirely sure what’s causing this and I would really appreciate help from you!

Thanks a lot :smile:

Your pastebin is an array that has keys, however only dictionaries can have keys. Switch the brackets on the top level to braces.

    ["ProCode"] = {
        "Prize" = "Box", 
        "Value" =  1,
    ["ProCode2"] = {
        "Prize" = "Box", 
        "Value" = 2, 
1 Like

Tried both methods, { } doesn’t work either :confused:

You’re not even using JSON format in your pastebin…

My bad, you also have to remove the brackets around the keys, and replace the = with :. This should work:

	"ProCode": {
		"Prize": "Box",
		"Value": 1
	"ProCode2": {
		"Prize": "Box",
		"Value": 2

Doesn’t require JSON format. Regular text works fine.

That’s the issue! It works now. Thank you a lot! :slight_smile:

1 Like

I’m saying you put a lua dictonary in a pastebin and then ran JSONDecode on it (which obviously doesn’t work because their syntax is entirely different)

Yeah, I noticed that right after the solution I got.
Didn’t know that I had to pull it off with the JSON format to be honest. Never used it but I appreciate the help :smile:

Pastebin is forbidden by Roblox. Please move to other versions.