How Can i fix "Can't Parse JSON"?

Hi there, i was making a system using github and it requires JSON.

Everytime the game runs, It hits me hard with the error “Can’t Parse JSON”

I tried fixing everything but it didnt work.

Here is the code:


local HTTP = game:GetService("HttpService")

local RepositoryName = "PacketDataStorage"
local GitHubAccountUsername = "jojogamezHub"

local StorageURL = "https://github.com/jojogamezHub/PacketDataStorage/tree/main/PacketData/"

local function GetPacketData(FilmName)
	warn("Getting Packet Data:",FilmName)

	local PacketData = {}

	local Config
	
	local PreConfig

	repeat

		local Success,ErrorMsg = pcall(function()

			local URL = string.format(StorageURL .. "%s/%s",FilmName,"config.json")
			
			local EncodedData = HTTP:GetAsync(URL)
			print("Got Config")
			Config = HTTP:JSONDecode(URL)
		end)

		if not Success then warn(ErrorMsg) task.wait(1) end

	until Success

	local Packets = Config["packets"]

	
	local TotalFrameIteration = 0
	
	
	print("Getting",Packets,"Packets")
	local PrevProgressPercent = 0
	
	for PacketIndex = 1,Packets do
		
		local ProgressPercent = math.floor((PacketIndex/Packets)*100)
		if ProgressPercent > PrevProgressPercent then print("Progress:",ProgressPercent .."%") PrevProgressPercent = ProgressPercent end
		
		local URL = string.format(StorageURL .. "%s/%s",FilmName,PacketIndex .. ".json")

		local DecodedData

		repeat

			local Success,ErrorMsg = pcall(function()
				local EncodedData = HTTP:GetAsync(URL)
				
				DecodedData = HTTP:JSONDecode(EncodedData)
				
			end)

			if not Success then warn(ErrorMsg) task.wait(1) end

		until Success
		
		PacketData[PacketIndex] = DecodedData
		
		--[[for _,FrameData in ipairs(PacketData) do
			
			TotalFrameIteration += 1
			
			for XNum, XData in ipairs(FrameData) do
				for YNum, YData in ipairs(XData)do

					FrameData[XNum][YNum] = Color3.fromRGB(YData[1],YData[2],YData[3])

				end
			end
			
			PixelData[TotalFrameIteration] = FrameData
			
		end]]

	end
	
	
	

	return Config,PacketData

end

local FilmData = {

	{
		["FilmName"] = "TheBeatdown",

		["SoundId"] = 0,
		["SoundVolume"] = 10,
		["PlaybackSpeed"] = 1,
	}

}

local PacketData = {}

local NumFilms = #FilmData
for i,Data in ipairs(FilmData) do -- format data

	local FilmName = Data.FilmName
	
	PacketData[FilmName] = {}
	
	Data["Config"],PacketData[FilmName] = GetPacketData(FilmName)


	FilmData[FilmName] = Data

	FilmData[i] = nil
	
	if i < NumFilms then
		task.wait(5) -- cooldown
	end


end

local Data = {
	["FilmData"] = FilmData,
	["PacketData"] = PacketData,
}

return Data



I need help as i am trying to get rid of the error and let the script run.

You tried to decode the URL, that might be the problem

The url is a direct link to the json file, dont tell me roblox cant parse a json file. Thats just Stupid.

It can decode a json file, but you tried to decode the URL (PacketDataStorage/config.json at main · jojogamezHub/PacketDataStorage · GitHub)

You should decode EncodedData

Config = HTTP:JSONDecode(EncodedData)

JSONDecode already requests a json file to parse so you must first get the json file with a get request

Config = HTTP:JSONDecode(HTTP:GetAsync(URL))

Like this? if not please give me an example.

Yes that’s what you must do but if the endpoint needs a “key” to grant the data you must provide headers

Oh ok, ima try this. Thanks a lot!

Nope, Same error. It didnt work.

At this point are you sure that you are receiving a json file?

Yes:

I literally tested the link by copying and pasting it in the browser. It gives me a json file.

I think i need to send you a place file.

Ohhh wait aren’t you requesting a not raw file? Not raw files other than the json content also have the web page html code

i tried that… it ends up giving me the 404 error code (Not Found error) or the 400 (Bad Request) or the 401… I’ll just send you the place file. Everytime i tried, It keeps throwing an error at me. After i send it, ill try getting the raw ver.

The raw link should look like this: raw.githubusercontent.com/username/RepoName/branchName/fileName

Ok i have an idea, lemme change the URL value to the raw link of the json file.

Yes that’s what I saw two post ago make sure to put https:// in front of raw.

What the hell?! its giving me the 404 error…

Alright to get to the raw page go to the json file from the Github website then click raw and copy the url

thats what i did. Thats the weird part.

Ok, i forgot to slap in String.Format… which caused it to break. It works now :smiley: