JSON Data Format

JSON (JavaScript Object Notation) is a text, formatted according to specific rules. A person can easily read it, and a computer can quickly process it. JSON is used to transmit and store information.

{
    "i_am_json_key": "I am json value"
}

Example of text in JSON format

Example of a JSON object

In everyday life, we often describe objects by their characteristics — for example, a cat has a name. A JSON object follows this idea and describes the object's properties as key-value pairs.

key — is the name

value — the information stored under that key

For example, a JSON object can contain

Key Value
name Mia
age 2
character_traits
friendliness
playfulness
cat-mia
Example of data in JSON format

Rules for Forming a JSON Object

Curly braces denote the beginning and end of the JSON object body
{

}
All keys are enclosed in double quotes
{
  "ключ": "значение"
}
String values are enclosed in double quotes
{
  "ключ": "строковое значение"
}
Numeric values are written without quotes
{
  "ключ": 1
}
Square brackets are used to denote an array of homogeneous data
{
  "ключ": [
    "строковое значение 1",
    "строковое значение 2"
  ]
}
Key names are commonly written using snake_case
{
  "ключ_из_нескольких_слов": "значение"
}

You can read more about JSON formatting rules at json.org.

Header Content-Type: application/json

Earlier we discussed what the HTTP protocol is and learned that HTTP requests and responses can contain additional information — headers.

Header Content-Type define the type of transmitted content and can have values like:
  • text/html
  • image/jpeg
  • application/json
  • and others...

When transmitting data in JSON format, it is necessary to specify the header Content-Type: application/json.

content-type
Content-Type Header of HTTP Request in DevTools
Task

Form a valid JSON from the given data:

Key Value Type
name Muffin string
age 3 number
favourite_toys
yarn ball
feather wand
array of strings

When the "Send" button is clicked, an HTTP request is sent, which can be viewed via DevTools.

Pay attention to the Content-Type header value. In the Payload, you will find the body of the request — the JSON you formed.

Enter data in JSON format:
:
[
Sidebar arrow