Table saves index as a string/dictionary instead of as a number index

If you’re using JSONEncode (or a lot of other Roblox things that process tables, since from what I’ve seen, most Roblox APIs that cross the VM state boundary, encode a table as JSON, then decode it on the other side), unless the table explicitly has a list with ordered keys (from 1… onwards), the JSON encoder assumes its a string key.

This is obviously because JSON doesn’t let you define numeric keys in an object.

{
  3: "a" // this is invalid syntax
}

And you also cant have mixed tables in JSON, you can only have or the other, maybe the encoder should really do this:

[null, null, item]

But this feels very niche (and could have dragons with performance), so the JSON encoder would rather just encode 3 as "3", since its calling tostring on the index, to get a string-encodable value, and the process is non-reversable (since “3” is very much a valid key)

3 Likes