How to convert string value to table?

An example would be item.Value = "{{..., ...}, {..., ...}, {..., ...}}", then convert it to a table. The only solution that I tried was to use gmatch '[^,]+', I’m not really familiar with format/string pattern:

for item in string.gmatch(items.Value, '[^,]+') do

But this does not recognize {}, and if I insert the item to the table and print it the output would be:

..., ..., ..., ..., ..., ... --- The output they are not sparate.

Of course I can just skip the next item, that did work but I want to use the gmatch.

If you haven’t tried this yet I highly recommend using the function:

It basically turns the string into a table.

2 Likes

Thanks I got it to work but you still need to assign a value to every key,

local value = [[
{
"1": {"1": "item1", "2": 1, "3": 2},
"2": {"1": "item2", "2": 1, "3": 2},
"3": {"1": "item3", "2": 1, "3": 2}
}
]]

local httpService = game:GetService("HttpService")

local data = httpService:JSONDecode(value)
print(data)

Is there like an alternative way to do it without assigning a key every time you add value?

Oh NVM using JSONEncode and decode it works.