JSON Tutorial - nonnymoose/QuizBot GitHub Wiki

Intro

All quiz files are in Javascript Object Notation, or JSON for short
Anything inside {} is an object

Objects

Objects have keys and values, separated by a colon
Key names must be in quotation marks.
Object values can be any of the following:

  • true/false (lowercase)
  • a number
  • a string of characters (in quotes)

Example:

{
    "key": "value"
}

If you want to have multiple key/value pairs in a JSON file, separate them with commas:

{
    "key": "value",
    "number": 42,
    "string": "Strings are characters inside quotation marks.",
    "truefalse": true
}

Note that you do not put a comma after the last attribute, and that numbers and true/false values are not in quotes

Arrays

If you want to have a series of values instead of just one, it's called an array, which looks like this:

{
    "array": ["value1", "value2", "value3"]
}

You can also have additional objects as in values or in arrays:

{
    "array": ["value1", "value2", {"subobjectKEY": "value"}]
}

which also have key/value pairs


Previous | Next