Skip to main content
Basic Knowledge of MIDAS API Created Edited

Terminology: JSON(JavaScript Object Notation)

shutterstock_1871534536.jpg

JSON is a lightweight data format for exchanging data. It consists of a text-based form to understand easily for people and machines.

 

What is JSON?

JSON stands for JavaScript Object Notation, a lightweight form to express data. JSON comprises “Attribute”: “Value” pair format, and it can indicate the data format simply. That’s why JSON is widely used in these days.

 

The features of JSON

᛫ Readable: Human readable and easy-to-understand text format.

᛫ Lightweight: Saving and transferring data is effective and less load than other formats.

᛫ Language independence: JSON is supported in various programming languages and is ideal for transferring data among other languages.

 

Structure of JSON

(1) The Basic Structure

JSON data classifies data according to bracket.

᛫ { } for Object

᛫ [ ] for Array

Example of Object

{ "name" : "Alice" }

Example of Array

[ "white", "red", "yellow", "green", "blue" ]

 

(2) Data Type

JSON has core data types as follows.

᛫ Key- Value(Attribute-Value) pairs.

᛫ Object: A collection of unordered key-value pairs.

᛫ Array: A collection of ordered key-value pairs.

 

(2.1) Key-Value (Attribute-Value Pair)

The key is located on the left side of the colon(:), string, and cover with pair quotation marks. Value is located on the right side of the colon(:).

Example

{
    "name": "Alice",
    "age": 25,
    "city": "New York"
}

 

(2.2) Object

The Object covers curly braces and consists of more than one Attribute-Value pair. They don’t have order, classify using commas, and enable to include in other Objects or Arrays.

Example

{
    "name": "Bob",
    "age": 30,
    "address": {
        "street": "123 Main St",
        "city": "Los Angeles"
    }
}

Example with Array

{
    "name": "John",
    "age": 35,
    "languages": ["JavaScript", "Python", "Java"],
    "address": {
        "street": "123 Main St",
        "city": "Exampleville"
    }
}

Example with other objects

{
    "person": {
        "1": {
            "name": "Alice",
            "age": 28,
            "city": "New York"
        },
        "2": {
            "name": "Bob",
            "age": 35,
            "city": "Los Angeles"
        }
    }
}

 

(2.3) Array

The Array covers brackets and consists of more than one Attribute-Value pair. They have order, classify using commas, enable to include in other Objects or Arrays, and have index begin with 0 or 1.

Example

{
    "person": {
        "name": "Alice",
        "age": 28,
        "hobbies": [
            "reading",
            "hiking",
            "painting"
        ],
        "address": {
            "street": "123 Main St",
            "city": "New York"
        }
    },
    "pets": [
        {
            "type": "dog",
            "name": "Buddy"
        },
        {
            "type": "cat",
            "name": "Whiskers"
        }
    ]
}

 

(3) Data Type

The data type is located on the right side of the Attribute-Value pairs and allows types as follows:

᛫ Object

᛫ Array

᛫ String

᛫ Number

᛫ Boolean

᛫ Null (explicit absence)

From this part, let’s look into string, number, and boolean data types.

 

(3.1) String

The String is covered with pair quotation marks and consists of empty or more than one uni-code text. Be careful; the String is covered with a single quotation mark, which is not valid.

There are several other escape characters you can use:

\”  Double quotation

\\  Backslashes

\/  Slashes

\b  Backspace

\f  Form feed

\n  Enter

\r  Carriage Return

\t  Tab

\u  This escape character is followed by a 4-digit hexadecimal number (Unicode character)

 

Escape characters are frequently used when representing folder paths as follows.

{
    "folderPath": "C:\\root\\documents\\projects"
}

 

(3.2) Number

Numbers are represented in a decimal system and cannot start with a 0. They may have a fractional part starting with a decimal point. Additionally, they can have an exponent with base 10, which is indicated using 'e' or 'E' notation along with a plus (+) or minus (-) sign. Numbers should not be enclosed in double quotation marks.

Example

{
    "year": 2023,
    "latitude": 40.7128,
    "longitude": -74.0060,
    "earth_distance_km": 1.496e8,
    "earth_distance2_km": 1.496e+8,
    "speed_of_light_mps": 3e+8,
    "speed_of_light2_mps": 3E+8,
    "atomic_mass_kg": 2.34e-27,
    "atomic_mass2_kg": 2.34E-27
}

 

(3.3) Boolean

The Boolean only has true or false data and isn’t covered with double quotation marks.

Example

{
    "isStudent": true,
    "isWorking": false,
    "isOnline": true,
    "hasLicense": false
}

 

(4) Usage of JSON

JSON is commonly used for data interchange between web applications and servers. It is widely utilized in RESTful APIs, web services, and web applications for transmitting and receiving structured data.

0
Was this article helpful?