피아노#98
피아노#98

How do I exchange my app usage information with the server? Essential IT knowledge, a complete guide to JSON!

JSON(JavaScript Object Notation) is a widely used data format for exchanging data between servers and clients in web and mobile app development.

  • Server : The brain of an IT service that processes data and provides it to the client

  • Client : The face of an IT service that interacts with users through web browsers and smartphones

The codefriends screen you are currently viewing and most web services and mobile apps around the world exchange data in JSON format. In this post, we will explore the basic concepts, structure, and usage of JSON.

What is JSON?

JSON is a data format used to represent data in the form of Key-Value pairs in JavaScript, a programming language used for implementing web services. Currently, various programming languages including JavaScript, Python, and Java support the JSON format.

The keys in JSON must be enclosed in double quotes (" "), and the values can be various data types such as strings (text composed of multiple characters) or numbers.

The Basic Structure of JSON

The structure of JSON consists of two main elements: Object and Array.

Object(Object)

Enclosed in curly braces { }, consisting of key-value pairs.

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

In the above JSON object, name, age, city are keys, and "John", 25, "New York" are the corresponding values for each key. For example, the value corresponding to the name key is "John".

Array(Array)

Enclosed in square brackets [ ], with values listed in order. An array can contain various data types including objects, strings, and numbers.

[
    { "name": "Alice", "age": 25 },
    { "name": "Bob", "age": 30 },
    { "name": "John", "age": 35 }
]

JSON Data Types

The data types that can be used as values in JSON format are as follows:

  • String : Text enclosed in double quotes "

  • Number : Numeric values such as integers and decimals

  • Boolean : Values representing true/false, true or false

  • Object : A group of data consisting of key-value pairs

  • Array : A collection of data listed in order

  • null : Indicates the absence of a value

JSON Example

The following JSON example represents a user named Alice with her name(name), email(email), friends list(friends), and activity status(isActive) in JSON format.

{
    "user": {
        "name": "Alice",
        "email": "alice@example.com",
        "friends": [
            { "name": "Bob", "age": 30 },
            { "name": "Charlie", "age": 35 }
        ],
        "isActive": true,
        "points": null
    }
}

By utilizing the JSON data format, user information, transaction history, and other data can be intuitively structured and represented.

Advantages of JSON

JSON has become the most widely used format for exchanging data in the IT industry due to the following advantages.

  • Readable format : Structured data in key-pair format makes it easy to understand the data structure intuitively

  • Lightweight : As a simple text format, it has a smaller size and simpler structure compared to XML, which follows a tag format like HTML, allowing for faster data exchange in web and app environments

  • Programming language compatibility : JSON is easily utilized in various programming languages such as JavaScript, Python, Java, and Ruby

Use Cases for JSON

JSON is useful in various situations. Typical use cases include:

  • Web API Communication : Using JSON format to exchange data between web servers and clients (browsers, smartphone apps)

  • Configuration Files : Storing app configuration information (e.g., dark mode settings, font size) in JSON files to structure the data

JSON is a standard data format that is essential to know for creating web and mobile IT services that interact with users.

Try creating your own IT service with Codefriends!

🔗 Codefriends Lecture List

APIJSON
Comment
No comment