JSON is a text format used to store and exchange data between applications. JSON stands for JavaScript Object Notation and is widely used because its structure is simple and easy for both people and computers to read.
JSON data is commonly organized into key-value pairs. The format can store different types of data, from text and numbers to arrays and objects.
What Is JSON?
JSON, or JavaScript Object Notation, is a format for organizing data as text. A simple JSON example looks like this:
{
"name": "Budi",
"age": 20,
"active": true,
"hobbies": ["coding", "gaming", "reading"]
}
In this example, "name", "age", "active", and "hobbies" are keys. Data such as "Budi", 20, and true are values.
This structure organizes the data so that each value can be identified by its key.
Keys and Values in JSON
One of the main concepts to understand when learning JSON is the key-value pair. A key serves as the name or label for a piece of data, while the value contains the information being stored.
For example:
{
"name": "Andi",
"class": "Web Programming"
}
Here, "name" is a key with the value "Andi", while "class" has the value "Web Programming".
This pattern allows data to be organized consistently and makes it easier to read.
Supported Data Types
JSON can store more than text. JSON values can be strings, numbers, booleans, arrays, objects, or null.
Strings and Numbers
A string stores text, while a number stores a numeric value.
{
"name": "Budi",
"age": 20
}
"Budi" is a string, while 20 is a number.
Booleans
A boolean stores either true or false.
{
"active": true
}
In this example, the key "active" has the boolean value true.
Arrays
An array is used when a key needs to store several values.
{
"hobbies": ["coding", "gaming", "reading"]
}
The key "hobbies" stores several items in a single array.
Objects
JSON can also contain objects nested inside other objects. This structure is useful when a piece of data has additional related information.
{
"name": "Andi",
"class": "Web Programming",
"address": {
"city": "Denpasar",
"province": "Bali"
}
}
In this example, "address" has an object as its value, containing the keys "city" and "province".
How Is JSON Used on Websites?
JSON can be used to exchange data between applications. One example is when a website's frontend receives data from a server.
A server might send student data in the following format:
{
"id": 1,
"name": "Kevin",
"course": "Python Programming"
}
JavaScript can then read this data and use it to display student information on the website.
JSON provides a clearly structured format for organizing and exchanging data between applications.
Why Is JSON's Structure Easy to Understand?
JSON's structure is relatively easy to recognize because each piece of information has a clear key and value. The following example lets us immediately identify a student's name and course:
{
"name": "Kevin",
"course": "Python Programming"
}
The format can be read by people and processed by computers. This makes JSON practical when an application needs to store or exchange data.
Frequently Asked Questions
What does JSON stand for?
JSON stands for JavaScript Object Notation, a text format for storing and exchanging data between applications.
What are keys and values in JSON?
A key is the name or label of a piece of data, while the value is its content. For example, in "name": "Budi", "name" is the key and "Budi" is the value.
What data types does JSON support?
JSON supports strings, numbers, booleans, arrays, objects, and null.
Learn More About JSON
JSON is an important format to understand when starting to learn web development and data processing. Understanding keys, values, arrays, and objects makes it easier to read the data structures used in applications.
Want to explore JSON and other programming topics? Learn with us at Koding Akademi and find more learning materials at https://www.kodingakademi.id/.