Run it
Copy the script and paste it into your executor.
gsub, format, rep, sub, split, match, gmatch = .gsub, .format, .rep, .sub, .split, .match, .gmatch;
tinsert = .insert;
floor = .floor;
, = , ;
base62_chars =
base62 = {
index = {};
}
i = , #base62_chars
base62.index[(base62_chars, i, i)] = i -
base62.(num)
str = (num);
#str == str
num = (num);
result =
num >
remainder = num %
result = (base62_chars, remainder + , remainder + ) .. result
num = (num / )
result
base62.(str)
result =
i = , #str
char = (str, i, i)
value = base62.index[char]
result = result * + value
result
cJ = {
characters = {
[] = utf8.(),
other = utf8.(),
numbers = utf8.()
}
};
re = {
sub = (, pattern, replacement)
pattern = (pattern, , (a, b)
(a, (b))
)
(, pattern, replacement)
,
secure = ()
StrList = ;
List = {};
_, Letter , (StrList, )
List[Letter] = .. Letter
(, , List)
}
cJ:(Raw)
start = ();
Text = (Raw, , )
Text = (Text, , (s1, a, s2)
a = (a, , )
a = (a, , )
s1 .. a .. s2;
)
Text = (Text, , (Spaces)
#Spaces <=
Spaces
cJ.characters[] .. #Spaces
)
LastLetter =
CurrentSequence =
LetterHistory = {}
i, Letter , (Text, )
Letter == LastLetter
CurrentSequence = CurrentSequence .. Letter
#CurrentSequence >
LetterHistory[LastLetter] = LetterHistory[LastLetter] {}
(LetterHistory[LastLetter], {start = i - #CurrentSequence, length = #CurrentSequence, sequence = CurrentSequence})
CurrentSequence = Letter
LastLetter = Letter
Letter, Data , LetterHistory
_, LetterData , Data
StartIndex, EndIndex = LetterData.start, LetterData.start + LetterData.length
Text = (Text, , StartIndex) .. Letter .. cJ.characters.other .. (LetterData.length) .. cJ.characters.other .. (Text, EndIndex)
Text = (Text, , (Number)
encoded = base62.(Number);
char = cJ.characters.numbers
#Number > #encoded +
char .. encoded .. char
)
{BytesCompressed = #Raw - #Text, Result = Text, TimeTaken = () - start};
cJ:(Text)
Raw = (Text, cJ.characters[] .. , (Times)
(, Times)
)
Raw = (Raw, .. cJ.characters.other .. .. cJ.characters.other, (Data, Times)
(Data, Times)
)
Raw = (Raw, cJ.characters.numbers .. .. cJ.characters.numbers, base62.decode)
Raw;
cJ;cJSON is a script that helps developers reduce file sizes, whethere it is beautified JSON, JSON that was obtained from websites via pretty print, or just any JSON data. It uses simple techniques to compress text, such as sequences of the same letter with 4 bytes, 2 bytes to mark the compression, 1 to mark how many times to duplicate it, and 1 aka the original letter. Of course it only does that IF the 4 bytes are shorter than the original sequence, so it wont work for 3 letter and below sequences. It also uses base62 encoding for numbers to decrease their sizes! For example, take the number 1234567890, base62 converts it to 1ly7vk which is only 6 bytes (4 bytes shorter than the actual number), And then you can add 2 to the total length which marks the string as base62 encoded. Usage: cJ:Compress(Data: string): table -> {BytesCompressed: number = 0, Result: string = "", TimeTaken: float = 0.000000} cJ:Decompress(Data: string): string -> Decompresses already compressed cJSON. Feel free to DM me about any issues on my discord.