Can't parse JSON for grabbing code from github?

Hello DevForum!

So I’ve been working on a module install system, but I keep getting this error after running

  16:29:29.950  Can't parse JSON  -  Studio - install:34
  16:29:29.950  Stack Begin  -  Studio
  16:29:29.950  Script 'user_lua.console.rbxmx.lua.console.PluginManager.Commands.Glass.glass.install', Line 34  -  Studio - install:34
  16:29:29.950  Script 'user_lua.console.rbxmx.lua.console.PluginManager.Commands.Glass.glass', Line 40  -  Studio - glass:40
  16:29:29.950  Script 'user_lua.console.rbxmx.lua.console.PluginManager', Line 116  -  Studio - PluginManager:116
  16:29:29.951  Stack End  -  Studio

Here is my code currently

local req = ""
		
if args[2] == "Test" then req = http:GetAsync("https://api.github.com/repos/acuaro-codes/test") end
		
local json = http:JSONDecode(req)
		
for i = 1, #json do
	local file = json[i]
	if (file.type == "file") then
		local name = file.name:sub(1, #file.name-4)
		local module = Instance.new("ModuleScript")
				
		module.Name = name
				
		module.Source = http:GetAsync(file.download_url)
		module.Parent = script.Parent.Parent.Parent
	end
end

Currently, I’m not handling missing stuff, but my input is glass install Test, and it just throws this error.

The only other article I could find about this is this one, but I couldn’t get any use out of it.

I’m new to the GitHub API so let so please let me know if I am requesting something wrong or should change a certain thing, thanks in advance!

1 Like

Do you have Http Requests enabled?
Sorry I don’t know how this works but I have a feeling it’s related to this

1 Like

Yup! They are on, sorry, should’ve clarified in the post!

I would print req to make sure you are actually parsing the data and making sure its actually needed since if the github returns text you wont need to parse it. It could also be your not specifying headers, methods, etc.

1 Like

It’s not letting me print it after doing

print(req)

The console is just blank and puts out the can’t parse JSON error

ALSO, if you check https://api.github.com/repos/acuaro-codes/test
It seems to be JSON

There’s two spaces after JSON there, because req still is "".

Probably args[2] is not actually "Test". Did you remember that lua uses 1-based indices? :slight_smile:

Also you can use the debugger to step through line by line and watch the variables change.

1 Like

SHOOT ARGS[2] IS INSTALL, NOT “TEST”, THATS ARGS[3]

Thanks so much!

2 Likes

What does this script do? am very interested!

1 Like

Hey! This is for lua.console, a console plugin for ROBLOX studio! I have commands like rm, insert, create, etc, and this is for my package manager. The hope is people will be able to create their own commands, similar to npm :smiley:

If your interested you can scroll down in the What are you working on 2021? category and I made some progress posts there!

Screenshots

Screen Shot 2021-03-06 at 7.51.05 AM "]
Screen Shot 2021-03-06 at 7.51.42 AM

2 Likes