I’m having issues when using HTTP to get JSON data:
I requested the data and it returned a string like: “{“user1”, “user2”}”
How would I turn that into a table?
Edit: :JsonDecode() does nothing but spit an error
I’m having issues when using HTTP to get JSON data:
I requested the data and it returned a string like: “{“user1”, “user2”}”
How would I turn that into a table?
Edit: :JsonDecode() does nothing but spit an error
Is that the exact string being output? The quotes look unusual but that could just be your computer auto-formatting them.
Next issue is that’s not valid JSON, JSON is key/value like
{
"name": "user1",
"userId": 12345
}
so if your string is more like an array, you’re better off just stripping the curly braces and performing a string.split like so
local function decode(data: string): {string}
local withoutCurlys = data:sub(1, #data-1)
local userTable = withoutCurlys:split(",")
return userTable
end
the list is a json on github thats formatted like this
{
["usernames"]: {
"username1",
"username2"
}
}
should i just reformat the json better?
Yeah that’s not quite correct. In JSON you can have an array but it has to be of key, value pairs.
I think based on what you’re looking at, it might be something like:
{
[
{
"name" : "username1"
},
{
"name" : "username2"
}
]
}
That’s just a rough example, it can be simplified but should give you an idea. You can probably also find more about JSON nuances online but this might be a good start
alright thank you
i will try that later and see how it goes