Get line from table when the line has two words

It’s probably simple enough, but basically, I have an API script that comes back as a table, problem is is that the table it comes back as a line with more than one word (“Global Quote” rather than “GlobalQuote” ). And, in order to get data from it as you can see on line 16, I need to be able to well, call it.

Script:

local Api_Stock = script.Parent.Ticker.Value
local Api_Key = 'API Key Here'
local Api_Url = 'https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol='..Api_Stock..'&apikey='..Api_Key
local HS = game:GetService("HttpService")


local Data
local s, e = pcall(function()
	Data = HS:GetAsync(Api_Url)
end)



if Data ~= nil then
	Data = HS:JSONDecode(Data)
	local Current = tostring(Data.GlobalQuote[05])
end

Data["Global Quote"][05]

You can index keys/fields which contain whitespace characters by doing the above.

This didn’t work, no errors, just didn’t work when I had it print current

Can you iterate over Data and print its keys & values so I can see how it’s formatted?

There’s likely some other issue at hand which I won’t be able to determine without seeing how the JSON decoded Lua table is structured.

This is how Data comes back

  15:24:54.603  {
    "Global Quote": {
        "01. symbol": "DIA",
        "02. open": "331.7500",
        "03. high": "334.6000",
        "04. low": "328.7900",
        "05. price": "330.0700",
        "06. volume": "5627894",
        "07. latest trading day": "2022-03-14",
        "08. previous close": "330.0200",
        "09. change": "0.0500",
        "10. change percent": "0.0152%"
    }
}  -  Server - API_Script:12

Yeah, [05] isn’t a valid index.

Do print(Data["Global Quote"]), it should print the table’s address in memory.

You need to index that table’s key named ["05. price"].

Okay So, I had two print statements in the script and I discovered once I deleted the one that wasn’t in the

if Data ~= nil then
	Data = HS:JSONDecode(Data)
	print(Data["Global Quote"])
end

part of the script isn’t printing at all.

Well that means Data is nil.

Any idea why Data is nil?