Answered by
6 years ago Edited 6 years ago
Data structures (such as tables) are automatically encoded to JSON upon set request to ROBLOX's data store service. For instance, there is no difference between...
1 | DataStore:SetAsync(key, table) |
and
1 | DataStore:SetAsync(key, JSONEncode(table)) |
Encoding a table with JSON for the purpose of saving is redundant.
However
Although you don't need to encode a table in JSON to save it, you may want to. There is a character limit to the JSON-formatted data that you can save under one key (I think it's 2^16 characters or something like that). So, perhaps one might want to encode a table before saving it to check the length of the encoded data to see if it will save successfully. For example...
01 | local HttpService = game:GetService( "HttpService" ) |
04 | local JSON_table = HttpService:JSONEncode(table) |
07 | if (#JSON_table > = 2 ^ 16 ) then |
This is just one out of other potential uses of encoding data in JSON before saving it. I hope this helped. If you have any questions, just let me know.
Disclaimer:
This is based off of my old knowledge of DataStoreService
. Although I don't think any of this has changed, I will update this answer accordingly if I find out any new information.