Skip to content
The Ghost in the Machine edited this page Jan 20, 2018 · 2 revisions

JSON

What is JSON?

JSON is a data file format, the same way .txt or .zip is.

Where to create JSON?

For creation of JSON files you may use any text editor you wish, although use of MS Notepad is discouraged upon. If you are looking for more complex solution that you can easy implement with the rest of our workflow, and you are potentially even thinking about improving the engine of the game, our recommended tool is IntelliJ IDEA (Community).

What to put into JSON?

Each JSON file starts with { and ends with }. Inside those, there may be an unlimited amount of key-value pairs. If you don't know what key-value pairs are, imagine the following: You are working in a large conference areal, and there is conference taking place right now. You carry a list of all the attending organizations with you at times, where you got listed the room organization is showcasing in along with its name. This way, if anybody happens to ask you 'Where is the organization XYZ', you can simply look up that name in the list and answer with the correct room. In this example, the 'key' was the organization name, something you can easily look up in list, and the 'value' was the conference room, or basically anything that could have interested you in connection with the organization-the key. In JSON, the key must be always of a String type, which means some word enclosed in double quotes, like "key". Value may than be of any type, which will be discussed later. Each key is separated from its value with colon :, and individual key-value pars are separated by commas ,. You can also insert new lines and spaces wherever you want to make the file more readable. Thus, some example JSON file may look like this:

{
  "organizationName": "MovingBlocks",
  "organizationGame": "DestinationSol",
  "gameLeader": "The awesome leader vampcat"
}

What are JSON value types?

In JSON, keys can be only of type String. However, values can be of any of the following listed types:

Type Example Explanation
String "The awesome leader vampcat" Some word or sentence, enclosed within double quotes ""
Number 42 Some number,which may or may not contain decimal part
Boolean true One of the values true or false
Array ["vampcat", 42, true] An array is an arbitrary amount of values enclosed in [], separated by commas ,
Object {"name": "DestSol", "array": [5,6]} Object is a value, that may itself contain an arbitrary amount of key-value pairs. You can think of objects as of new JSON files.

Example JSON

Now, you should have a basic idea of how JSON file should look. To sum all these things up, there is some example JSON showcasing all the features mentioned above:

{
  "displayName": "Federal battleship",
  "price": 500,
  "playable": true,
  "possibleCaptainNames": [
    "Jack",
    "John",
    "Steve",
    "Kirk",
    "Picard"
  ],
  "drone": {
    "type": "repair",
    "level" 2
  },
  "engines": [
    {
      "position": {
          "x": 3.152,
          "y": 4.987
      },
      "thrust": 8
    }, {
      "position": {
          "x": 5.211,
          "y": 1
      },
      "thrust": 0.00001
    }
  ]
}