Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Compress your project.json file!
- davidtheplatform
-
Scratcher
500+ posts
Compress your project.json file!
I made a python script that reduces the size of the project.json file in your projects to about 80% of the original size. You can download it here:
Steps to use it:
1. Make sure you have Python 3 installed
2. Download the main.py script and put it in an empty folder
3. Put an sb3 file in the folder and call it ‘project.sb3’
4. Run the script
The ‘compressed.sb3’ file will have a smaller project.json file in it!
Running the script on a project that you already compressed does not do anything.
If you find a bug, please add a link to the project that causes the bug!
https://replit.com/@theplatform/scratch-json-compressor
Steps to use it:
1. Make sure you have Python 3 installed
2. Download the main.py script and put it in an empty folder
3. Put an sb3 file in the folder and call it ‘project.sb3’
4. Run the script
The ‘compressed.sb3’ file will have a smaller project.json file in it!
Running the script on a project that you already compressed does not do anything.
If you find a bug, please add a link to the project that causes the bug!
Last edited by davidtheplatform (Nov. 16, 2022 01:07:02)
- oxiti8
-
Scratcher
1000+ posts
Compress your project.json file!
FYI, that link you gave is a 404 because the “@” gets replaced with “%40”.
Also, could you give rundown on what exactly this does to the project.json (ex. does it or does it not clear out the values of lists/variables, does it clear the numbers “under” operator arguments when a block is covering them, etc.)
Also, could you give rundown on what exactly this does to the project.json (ex. does it or does it not clear out the values of lists/variables, does it clear the numbers “under” operator arguments when a block is covering them, etc.)
- davidtheplatform
-
Scratcher
500+ posts
Compress your project.json file!
Also, could you give rundown on what exactly this does to the project.json (ex. does it or does it not clear out the values of lists/variables, does it clear the numbers “under” operator arguments when a block is covering them, etc.)
It doesn't remove any data from the project, so if it works correctly the result is identical to the original just smaller.
How it works:
Every thing (a variable, block, sprite, etc…) in scratch has a unique id. This id is used when you want to operate on something that isn't a constant.
This:
set [foo v] to [5]
would be represented like this in the project.json file:
"S+O{$1TbTv:]mD2[{n8Y":
{
"opcode": "data_setvariableto",
"next": null,
"parent": null,
"inputs":
{
"VALUE": [1, [ 10, "0"]]
},
"fields":{
"VARIABLE":[
"my variable",
"`jEk@4|i[#*?(8x)AV.-my variable"
]},
"shadow": false,
"topLevel": true,
"x": 409,
"y": 401
}The two strings of random characters are ids of the block and a variable. These ids can be anything, but Scratch makes them long strings to avoid creating an object with an id that already exists. (They also separate variables with the same name). My script shortens these ids, so “S+O{$1TbTv:]mD2[{n8Y” would be replaced by “a”, and “`jEk@4|i[#*?(8x)AV.-my variable” would be replaced by “b”, and so on for all the other ids. This means that you can save ~30 bytes every time an id is used.
(small note: costumes and sounds have a longer id, but for them the id has to be a specific value so we can't shorten them.)
Last edited by davidtheplatform (Nov. 16, 2022 01:21:38)
- ZZC12345
-
Scratcher
500+ posts
Compress your project.json file!
Also, TurboWarp provides this feature by default when you save projects using it. But nice job!
(small note: costumes and sounds have a longer id, but for them the id has to be a specific value so we can't shorten them.)Since the id for costumes and sounds is the hash (MD5 or something?) of the asset's content.
- ScratchcatandGobo
-
Scratcher
1000+ posts
Compress your project.json file!
I made a python script that reduces the size of the project.json file in your projects to about 80% of the original size. You can download it here:Replit is banned from scratch. Also project.sb3 dosn't exist.https://replit.com/@theplatform/scratch-json-compressor
Steps to use it:
1. Make sure you have Python 3 installed
2. Download the main.py script and put it in an empty folder
3. Put an sb3 file in the folder and call it ‘project.sb3’
4. Run the script
The ‘compressed.sb3’ file will have a smaller project.json file in it!
Running the script on a project that you already compressed does not do anything.
If you find a bug, please add a link to the project that causes the bug!
Last edited by ScratchcatandGobo (Nov. 21, 2022 22:28:52)
- davidtheplatform
-
Scratcher
500+ posts
Compress your project.json file!
Replit is banned from accessing the scratch API, but you can still mention and link to it (i think, correct me if I'm wrong)
You have to upload a project.sb3, then run the repl.
You have to upload a project.sb3, then run the repl.
- Discussion Forums
- » Advanced Topics
-
» Compress your project.json file!