Converting a string with text and numbers into a Table with JSONDecode?

So I’m trying to figure out how to convert a string into a table.

So for example right now I have a string that’s just
"0,1,2,3,4"
This string then gets [ and ] added onto it and it becomes
"[0,1,2,3,4]"
And I can run JSONDecode on it just fine.
But when I try putting in like "[0,1,2,3,4,Text Title Here, 5]"
It just cant parse the JSON, is there something I do not understand about the format? Is there anything hacky I’d have to do to get this to work?

Unless Text Title Here isn’t a string, it should be completely fine to use, and should parse normally according to this test:

local HttpService = game:GetService("HttpService"); -- service

local lua_code = {1, 2, 3, 4, "Some Text Here", 5} -- Lua code
local json_code = HttpService:JSONEncode(lua_code); --  to JSON
-- yields result:
-- [1, 2, 3, 4, "Some Text Here", 5]
-- alternatively for the same result:
local json_code = `[1, 2, 3, 4, "Some Text Here", 5]`; -- works the exact same
-- comment out for the code above to work.

print(HttpService:JSONDecode(json_code)); -- Decode
-- yields result:
-- {
--    [1] = 1,
--    [2] = 2,
--    [3] = 3,
--    [4] = 4,
--    [5] = "Some Text Here",
--    [6] = 5
-- }

So its likely an issue on your part on how you’re adding the value to the json table.

1 Like

So it turns out what I was missing was the quotation marks for the text and I had no clue. Oops! Thank you very much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.