SandCastleIcon.png This page has links to websites or programs not hosted or created by Scratch or Wikipedia. Remember to stay safe while using the Internet, as we can't guarantee the safety of other websites.

JSON (JavaScript Object Notation) is a data format based on the syntax for JavaScript object literals.[1] It is used to store Scratch projects. A project in Scratch 2.0 is actually a ZIP archive of the media and a file named "project.json," which contains the scripts.

Syntax

Object

{"key1": value1, "key2": value2, ... "keyn": "valuen"}

In JSON, Objects are pairs of keys and values. The value can be obtained by the key, and therefore the key must be unique so that there is no confusion as to which value is being referred to. The JSON keys must be strings, but the values can be any types. Nested objects are allowed in JSON.

List

[item1, item2, ... itemn]

Similar to lists in Scratch, lists (also known as arrays) in JSON are an ordered sequence of elements. Lists can contain any type as their values, and nested lists are allowed.

Numbers

5.4

Numbers can be both positive and negative, and they can contain decimal points. They do not need anything around them—you can simply write them as they would be written normally

Strings

"the value of the string" Strings are an ordered series of characters. The characters may be any characters in unicode, with the exception of a few (though all characters can be represented), however some characters require backslash escaping.

Backslash escaping involves placing a backslash character in front of characters or a series of characters to change their meaning. In JSON, this can only be done within strings. For example, to make a " appear as a character in a string, it must be escaped or the JSON parser will confuse it for the closing character of the string. Replacing the " with a \" will fix the problem, as the backslash will remove the special meaning of the quote character. However, if \" should appear in a string literally, it needs to be escaped. Both the backslash and the quote needs to be escaped, and so a backslash must be inserted before both of them, \\\", to make it take its literal meaning of \".

Backslash escaping can also make characters that usually have no special meaning become replacements for other characters. For example, \n represents a newline.

How to find the JSON file of a project

By URL

One can fetch the JSON of a project, even if unshared, via this URL: http://projects.scratch.mit.edu/internalapi/project/PROJECTID/get/ with "PROJECTID" replaced with the id of the project of which to get the JSON file.[2]

For instance, if one would want to get the JSON file of a project with the URL "https://scratch.mit.edu/projects/123456789/" they would replace "PROJECTID" with "123456789" resulting in "http://projects.scratch.mit.edu/internalapi/project/123456789/get/"

From SB2

To acquire the JSON file of an .sb2 file, the file should be renamed to have an extension of .zip and then it needs to be extracted (unzipped). The contents of the unzipped folder should contain a project.json file, and this contains the JSON of the project.

Example JSON file

Here is what the JSON file of a brand new project created in the online editor looks like:

{
 "objName": "Stage",
 "sounds": [{
   "soundName": "pop",
   "soundID": 1,
   "md5": "83a9787d4cb6f3b7632b4ddfebf74367.wav",
   "sampleCount": 258,
   "rate": 11025,
   "format": ""
  }],
 "costumes": [{
   "costumeName": "backdrop1",
   "baseLayerID": 2,
   "baseLayerMD5": "739b5e2a2435f6e1ec2993791b423146.png",
   "bitmapResolution": 1,
   "rotationCenterX": 240,
   "rotationCenterY": 180
  }],
 "currentCostumeIndex": 0,
 "penLayerMD5": "5c81a336fab8be57adc039a8a2b33ca9.png",
 "penLayerID": -1,
 "tempoBPM": 60,
 "videoAlpha": 0.5,
 "children": [{
   "objName": "Sprite1",
   "sounds": [{
     "soundName": "meow",
     "soundID": 0,
     "md5": "83c36d806dc92327b9e7049a565c6bff.wav",
     "sampleCount": 18688,
     "rate": 22050,
     "format": ""
    }],
   "costumes": [{
     "costumeName": "costume1",
     "baseLayerID": 0,
     "baseLayerMD5": "09dc888b0b7df19f70d81588ae73420e.svg",
     "bitmapResolution": 1,
     "rotationCenterX": 47,
     "rotationCenterY": 55
    },
    {
     "costumeName": "costume2",
     "baseLayerID": 1,
     "baseLayerMD5": "3696356a03a8d938318876a593572843.svg",
     "bitmapResolution": 1,
     "rotationCenterX": 47,
     "rotationCenterY": 55
    }],
   "currentCostumeIndex": 0,
   "scratchX": 0,
   "scratchY": 0,
   "scale": 1,
   "direction": 90,
   "rotationStyle": "normal",
   "isDraggable": false,
   "indexInLibrary": 1,
   "visible": true,
   "spriteInfo": {
   }
  }],
 "info": {
  "flashVersion": "LNX 20,0,0,286",
  "swfVersion": "v443",
  "spriteCount": 1,
  "hasCloudData": false,
  "userAgent": "Mozilla\/5.0 (X11; CrOS x86_64 7647.73.0) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/48.0.2564.92 Safari\/537.36",
  "scriptCount": 0,
  "videoOn": false
 }
 }

References

  1. https://msdn.microsoft.com/en-us/library/bb299886.aspx
  2. https://scratch.mit.edu/discuss/post/1773451/