How to save a stringvalue table?

Hello! I want to save a stringvalue table.
I tried JSONEncode and JSONDecode.
But the decoding returned with this error.

13:06:34.625  Can't parse JSON  -  Server - Data:30

So here is the line that puts the encoded table from the stringvalue:

InventoryVariable.Value = Http:JSONEncode(Inventory)

And here is the line that decodes the stringvalue:

local inv = HttpService:JSONDecode(player.Inv.Value)

Can you show what Inventory is?

The inventory is where all of your cards go.
In other words the inventory is a table variable.

Can you show how Inventory is formatted? Maybe it’s cyclic or mixed.

Here is the format you were asking for:

local Inventory = {}

No, I meant how you were inserting cards. Can you try printing Inventory?

1 Like

I use table.insert()
Its the way i insert the cards into.

When do you get the parse error, when encoding or decoding? Could you print out the value you’re trying to pass through whichever method is erroring and post it as a response to the thread? Copy it from your output window. If there are any collapsed tables (the right-facing arrow) please expand them first (click on them) before copying them.

You have an invalid structure you’re attempting to pass to either one of these methods but there’s a severe lack of context to identify what the problem is. Saving StringValues is as simple as accessing their Value. In the first place, though, you don’t need to be using JSON when saving to DataStores so if that’s what you’re trying to do then don’t.

The output returns:

{
    [1] = "Card",
    [2] = "Card",
    [3] = "Card"
}

This alone doesn’t help, I had more questions than just “what do you get in your output”. Please refer to the post above so you can provide more context here - I also needed to know which side errors.

  • When do you get the parse error, when encoding or decoding?
  • Could you print out the value you’re trying to pass through whichever method is erroring and post it as a response to the thread?

Need to know when do you encounter this issue, during encoding or decoding, as well as what this print represents - the value that you’re trying to encode or the value you’re trying to decode.

Ok, Let me answer your 2 more questions.

  1. The parse error comes from decoding. I’m decoding a stringvalue that has a json object.
  2. The method that is erroring is the JSONDecode line. The json from the stringvalue that is being decoded dosent work.

Right, thanks. The parse error is, as I said:

This is a valid JSON structure that can be decoded:

["Card","Card","Card"]

If you got a table when you printed (and not just a string, like an actual table) then your value is already available to be used right away and there’s no point in trying to JSONDecode it because it’d still give you the parse error. You could sidestep it by checking what typeof returns on the value and only giving it to JSONDecode in a pcall .

Also to reiterate some advice:

So I think it’s best to fix the fundamental error of using JSON to begin with. You don’t need it.

1 Like

hmmm…
The stringvalue’s value is:

["Card","Card","Card"]

you can just do table[card name] = true , if you want to delete the string just do table[stringname] = nil