1. JSON Syntax

JSONarrow-up-right (JavaScript Object Notation), is a standard for representing structured data based on JavaScript's object syntax. It is commonly used to transmit data in web apps via HTTP. For example, The HTTP requests we have been making in this course have been returning Jello issues as JSON.

JSON supports the following primitive data types:

  • Strings, e.g. \"Hello, World!\"

  • Numbers, e.g. 42 or 3.14

  • Booleans, e.g. true

  • Null, e.g. null

And the following collection types:

  • Arrays, e.g. [1, 2, 3]

  • Object literals, e.g. {"key": "value"}

JSON is similar to JavaScript objects and Python dictionaries. Keys are always strings, and the values can be any data type, including other objects.

The following is valid JSON data:

{
    "movies": [
        {
            "id": 1,
            "title": "Iron Man",
            "director": "Jon Favreau",
            "favorite": true
        },
        {
            "id": 2,
            "title": "The Avengers",
            "director": "Joss Whedon",
            "favorite": false
        }
    ]
}

Assignment

Complete the issueList and userObject string constant values.

1

First step

issueList is a JSON array containing two issues (object literals). It should have the following issues:

ISSUE ONE:

  • id: 0 (number)

  • name: "Fix the thing" (string)

  • estimate: 0.5 (number)

  • completed: false (boolean)

ISSUE TWO:

  • id: 1 (number)

  • name: "Unstick the widget" (string)

  • estimate: 30 (number)

  • completed: false (boolean)

2

Second step

userObject is a JSON object literal that represents a Jello user. It should have the following fields:

  • name: "Wayne Lagner" (string)

  • role: "Developer" (string)

  • remote: true (boolean)

The tests simply check that the JSON is valid.

You can use a backtick (`) to create a multi-line string in Go. This will make it easier to write the JSON data.

Solution