Does it take up less space to store a bool value as a digit in json encode

So as an example, which of these two tables will take up the least amount of storage in a datastore?
t2 uses 0 to represent false, and 1 to represent true. While t1 just uses the bool value

local t1 = {
	["test"] = true
}
local t2 = {
	["test"] = 1
}
httpService:JSONEncode(t1)
httpService:JSONEncode(t2)
1 Like

number wins!! (aka t2 table wins)

local httpService=game:GetService("HttpService")

local t1 = {
	["test"] = true
}
local t2 = {
	["test"] = 1
}

print(string.len(httpService:JSONEncode(t1)),[[t1 check]])
print(string.len(httpService:JSONEncode(t2)),[[t2 check]])

Zrzut ekranu 2024-03-25 173800

5 Likes

True and False to a computer is 1 or -1, so they are the same size. That’s why that time test is exactly the same amount of time. Both are 1’s to the computer.

1 Like

Ah I see, after all it just becomes a string, maybe this was a bit of a stupid question of me haha, it was a bit obvious actually. Thank you for testing it though cheers!

1 Like

Not really stupid question, if you don’t know this stuff … you don’t know. True and false are actually called tokens. As .lua is an interpreted language. There is a mass token table that coverts your code at run time or when complied. Same thing hold true for other tokens like Red or Green.

1 Like

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