Hi guys, I’m trying to get an admin table from Pastebin (I wanted to use Pastebin because I wanted to be able to update admins without having to go in studio and shutting down the game, or using a datastore to admin/unadmin people)
I’m relatively new to how JSON works, so it’s entirely possible I formatted it incorrectly. Here’s my Pastebin: Bordr Admins - Pastebin.com
local HttpService = game:GetService('HttpService')
local BaseUrl = 'https://pastebin.com/raw.php?i='
local PastebinId = '5GtkaSUB'
local Admins = HttpService:GetAsync(BaseUrl..PastebinId)
print(Admins)
local AdminTable = HttpService:JSONDecode(Admins)
for i,v in pairs(AdminTable) do
print('Name: '..v.Name..'\nUserId: '..v.Id..'\nTitle: '..v.Title)
end
print(Admins) works correctly and prints the pastebin, but when I attempt to call JSONDecode on Admins it says it can’t parse the JSON.
I’m assuming @Sharksie is correct but I find that kind of silly so just in case:
Are you sure the JSON is valid? I tried decoding it with JavaScript and it doesn’t work there, either. I think it’s the single quotes, shouldn’t they be double quotes (“User”)?
It’s fine in JavaScript as well, but JSON isn’t JavaScript - JSON is very specific.
There’s also another issue, the trailing commas after all the Title fields have to be removed. That’ll also throw off the parser.
Should be fine after those two changes
Edit: Also, like Realbighead said, you’d need to change the first { and the last } into [ and ], respectively. Missed that one
Oh, okay. Usually when I do tables in Lua it doesn’t care if I leave a comma where it’s not needed, it’d still work fine. I’ll try that and let you know!
Yeah, Lua’s really lenient with stuff. Same with JavaScript. But JSON I think doesn’t really expect them to be user created (just - JSON Stringify, JSON Parse) so it expects things to be exact
In your JSON, you have to index the “User” key to get the name, id, and title. Just replace v.Name with v.User.Name (and do the same for id and title too)