Turning String value into table

  1. What do you want to achieve? Keep it simple and clear!
    I wanted to turn a string value that I have for the data into a table but it didn’t work

  2. What is the issue? Include screenshots / videos if possible!
    When I attempted to use JSONDecode it kept saying “JSON can not parse”

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked through forums and multiple sources of turning a string value into a table, they never worked out

Why couldn’t the JSON parse? What did your string look like?

I don’t know to much about JSON, I was setting up a talent card system where the talent cards that the player would choose would be stored in that value so I just added a few random cards that I made in there such as “Adapted Senses, Life Sense, etc.”. I correct set up the JSONDecode and everything, I still do not know how it errored

You should take another stab at it. JSONs sound like the way to go.
Just remember when using JSONs that they are a little different from Lua tables and they should be a little easier to debug.
Dictionaries (key/value pairs) use {} braces. Lists/arrays (just values) use [] brackets.

Here’s an example.
This is not Lua code, this is a JSON. You can’t put it directly in a script.

playerData: {
    "health": 90,
    "maxHealth": 100,
    "name": "John Doe",
    "inventory": [
        {
            "itemName": "sword",
            "damage": 4,
            "attackSpeed": 30
        },
        {
            "itemName": "gun",
            "damage": 2,
            "attackSpeed": 20,
        }
    ]
}

If you get the parse error again, feel free to ask questions and we’ll work out what’s causing the issue.

JSON uses colons to assign values to indices

{
   "foo": "bar"
}
1 Like

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