HttpService Help

I’m attempting to connect MongoDB to Roblox with HttpService, and I already have MongoDB connected with a website, however, I am having issues with GetAsync().

This is what GetAsync currently returns:

[{"confirmation":"Found","data":[{"username":"FreezeBall1","bannedby":"FreezeBall1","bantype":"3 days","reason":"cause why not","_id":"5eb0a78177c9fd65ef632a52","__v":0},{"username":"test","bannedby":"FreezeBall1","bantype":"test","reason":"test","_id":"5eb0b38dd6554168788a8810","__v":0}]}]

I am kind of new to using HttpService with things like MongoDB, so I’m not sure where to go from here. I’ve used JsonDecode and assigned it to a variable, but it’s acting up and not printing everything in the table when I try to loop through it.

If anyone knows how to properly do this, it would be appreciated.

HttpService:JSONDecode works fine for me in this example. What are you doing in your code?

local json = '[{"confirmation":"Found","data":[{"username":"FreezeBall1","bannedby":"FreezeBall1","bantype":"3 days","reason":"cause why not","_id":"5eb0a78177c9fd65ef632a52","__v":0},{"username":"test","bannedby":"FreezeBall1","bantype":"test","reason":"test","_id":"5eb0b38dd6554168788a8810","__v":0}]}]'

local stuff = game:GetService('HttpService'):JSONDecode(json)

print(stuff[1]['confirmation']) -- Found
print(stuff[1]['data'][1]['username']) -- FreezeBall1
1 Like

I was doing something like this to see if their name existed in the table, but it didn’t work the way I expected it to.

local HTTP = game:GetService("HttpService")
local URL = "private"
local DATA = HTTP:GetAsync(URL)
DATA = HTTP:JSONDecode(DATA)
for i,v in pairs(DATA) do
    print(i)
    print(v)
end

Edit: I tried using the method you did as well, and for some reason it’s not working.

Meant to do that but forgot. Thanks.

See I can view it

Yeah. Just in case I’ll probably get a new one.

Okay.
(30 CHARSRSRSRSRSsssSRSSS)

What do you mean by “it’s not working”? What kind of output do you expect to see? In your example, assuming DATA is the same json, it looks like it would print “1” then “table: 0x…” because the root of the json is an array with one dictionary in it.

Data[1] is returning nil for some reason when I tried one of the two lines you made.

local DATA = HTTP:GetAsync(URL)
DATA = HTTP:JSONDecode(DATA)
print(DATA[1]['data'][1]['username'])

Line five is the print statement.
image

I noticed in an earlier screenshot that the root element isn’t an array but the dictionary, so you could probably try DATA['data'][1]['username']. If that doesn’t work either, try adding print(DATA) before you use JSONDecode to see what it’s actually getting.

1 Like

Yeah. The one you put worked. Thanks.