Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to parse JSON?

Heyhoi! I somehow can't find the issue in this script I am trying to create:

local application = [[
	{
		"ApplicationName":"Moderator Application",
		"Desc":"Apply to become a moderator on hundreds of games today!"
	}
]]

local questions = [[
	{
		"Why do you want this job??",
		"Why should we hire you over others?"
	}
	
]]
local httpservice = game:GetService("HttpService")

application = httpservice:JSONDecode(application)
questions = httpservice:JSONDecode(questions)
print(application.Desc)

script.Parent:WaitForChild("Frame").Start.ApplicationName.Text = application.ApplicationName
script.Parent.Frame.Start.Information.Text = application.Desc


for i = 1,#questions do
	print("Started!")
	local clone = script.Parent.Frame.QuestionTemplate:Clone()
	clone.Parent = script.Parent.Frame
	clone.Name = "Question" .. script.Parent.Frame.CurrentQuestionNumber.Value
	
	clone.Question.Text = application.questions[i]
end

The first JSONDecode works fine, the second one gives an error: 23:43:03.027 - Can't parse JSON 23:43:03.029 - Stack Begin 23:43:03.029 - Script 'Players.marketmanager1.PlayerGui.ScreenGui.LocalScript', Line 18 23:43:03.029 - Stack End

I suspect the error is in the Json 'questions', but I have no idea what's wrong. The reason I am not using JSON Keys is because I want an array. ;)

Thanks in advance, Jonas

1 answer

questions is not a JSON string.

Arrays in JSON use []; you're using {} which requires key value pairs.

local questions = [[
["alpha", "beta"]
]]

In general because JSON could contain arrays of arrays like [[1, 2], [3, 4]] it might be a good idea to default to [=[ or [==[ etc as your long-string-literal delimiters.

This discussion is preserved as it was. New answers, comments, and votes are closed.