Skip to content

JSON Tips and Tricks

tterrag1098 edited this page Sep 2, 2014 · 1 revision

JSON is a wonderful data format, but it has some caveats that a newbie to the format might find confusing.

Firstly, to define an object, we use braces, {}.

Inside an object go fields. Fields are defined with their name (always in quotes) and their value. If the object only has one field defined, a comma is not needed, but for any more than one field, commas must separate them. Here is an example of a basic object:

{
    "field1": "I am a string!",
    "field2": true,
    "field3": 42
}

Note that the string field's value must be in quotes, while numbers and booleans do not need to be in quotes.

Most JSON files in KitchenCraft define an array of these objects, so each object that is not the last must have a comma between it and the next object. Here is a basic example of that:

[
    {
        "field1": "I am a string!"
    },
    {
        "field1": "I am a different string!"
    }
]

Finally, you may notice all KitchenCraft JSON files have a "root" object. Never alter the original content of the file other than adding objects inbetween the brackets. Doing so will prevent the loading of your file and likely crash the game.