JSON

From Minecraft Wiki
Jump to: navigation, search

JSON (JavaScript Object Notation) is a lightweight data-interchange format.[1]

In Minecraft, JSON format is used to store the following data:

Syntax[edit]

A JSON file must always contain opening and closing curly brackets which encapsulate all of the files data.

{
    "string": "Hi",
    "number": 1,
    "object": {"stuff": "foobar", "digit": 13},
    "array": ["spam", "foo"]
}

All element names in a JSON file must be contained inside quotes. To define a value, a colon is used after the name, followed by a value.

{
    "name": "value"
}

All elements except for the last element in an array or object should have a comma after their value.

Data types[edit]

There are 5 different data types in regular JSON: string, number, object, array, and boolean.

String[edit]

A string is defined by single or double quotes and can contain any combination of characters or spaces. Some special characters need to escape.

{
    "foo": "bar",
    "spam": "eggs"
}

Number[edit]

A number is defined by entering in any number.

{
    "two": 2,
    "one": 1,
    "second": 1
}

Object[edit]

Also referred to as a compound. An object is defined by opening and closing curly brackets and can contain any combination of any data types. Each contained value needs to have a name that is unique within the object. The required curly brackets at the beginning and end of a file make an object.

{
    "Bob": {
        "ID": 47182,
        "lastName": "Ramsay"
    },
    "Alice": {
        "ID": 47183,
        "lastName": "Berg"
    }
}

Array[edit]

Arrays are defined by opening and closing square brackets and can, again, contain any data types.

{
    "people": ["Bob", "Alice", "Carlos", "Eve"]
}

Boolean[edit]

A boolean can be either true or false.

{
    "Alice": {
        "isMale": false
    },
    "Bob": {
        "isMale": true
    }
}

References[edit]