Understanding JSON and Working with Data in Web Development

![[JS 강좌] 2강 - 개발 환경 구축하기 (VS Code, Chrome 개발자 도구)](/uploads/editor/JS-%EA%B0%95%EC%A2%8C-2%EA%B0%95-%EA%B0%9C%EB%B0%9C-%ED%99%98%EA%B2%BD-%EA%B5%AC%EC%B6%95%ED%95%98%EA%B8%B0-VS-Code-Chrome-%EA%B0%9C%EB%B0%9C%EC%9E%90-%EB%8F%84%EA%B5%AC-20260706-0dfe9b.webp)
What is JSON?
You'll frequently encounter the term JSON when working on web development.
JSON stands for
JavaScript Object Notation
It's a standard format for storing or exchanging data.
Most websites and mobile apps today use JSON to transfer data.
Where is JSON Used?
JSON is used in many places.
For example:
Login information
User profiles
Post listings
Comment lists
Product information
Weather data
Map services
AI APIs
REST APIs
Essentially, most web services use JSON.
Object vs. JSON
First, let's look at a JavaScript object:
let user = {
name: "홍길동",
age: 30
};
JSON looks very similar.
{
"name":"홍길동",
"age":30
}
However, there's an important difference:
In JavaScript objects, you can omit quotes around property names,
but in JSON, you must use double quotes (" ).
JSON Format Rules
JSON follows these rules:
Strings must be enclosed in double quotes
Keys must also use double quotes
Data items are separated by commas
No comma after the last item
Valid JSON
{
"name":"홍길동",
"age":30,
"city":"서울"
}
Invalid example
{
name:"홍길동"
}
Reading JSON Data
You can use it like an object.
let user = {
name:"홍길동",
age:30
};
console.log(user.name);
Result
홍길동
JSON String
In web applications, JSON is often sent as a string.
let json = '{"name":"홍길동","age":30}';
This is currently a string (String).
You can't use it like an object directly.
JSON.parse()
Converts a JSON string to an object.
let json = '{"name":"홍길동","age":30}';
let user = JSON.parse(json);
console.log(user.name);
Result
홍길동
This is one of the most commonly used functions in practice.
JSON.stringify()
Converts an object to a JSON string.
let user = {
name:"홍길동",
age:30
};
let json = JSON.stringify(user);
console.log(json);
Result
{"name":"홍길동","age":30}
This is commonly used when sending data to a server.
Arrays Can Be Represented in JSON Too
Let's take a forum listing as an example.
let posts = [
{
title:"첫 번째 글"
},
{
title:"두 번째 글"
}
];
In JSON format:
[
{
"title":"첫 번째 글"
},
{
"title":"두 번째 글"
}
]
This allows you to send multiple data items in array form.
Iterating Through JSON Data
posts.forEach(post => {
console.log(post.title);
});
Result
첫 번째 글
두 번째 글
This is a common method for displaying forum listings or product lists.
Nested JSON
In real-world scenarios, JSON often contains arrays or objects within other objects.
let user = {
name:"홍길동",
hobby:["축구","독서"],
address:{
city:"서울",
country:"대한민국"
}
};
Usage
console.log(user.hobby[0]);
console.log(user.address.city);
JSON Received from APIs
For example, assume a server sends the following data:
{
"result":"success",
"name":"홍길동",
"age":30
}
In JavaScript, you can use it like this:
console.log(data.result);
console.log(data.name);
Forum Data Example
Forum listings are typically in JSON format.
[
{
"title":"JavaScript 시작하기",
"writer":"관리자"
},
{
"title":"DOM 배우기",
"writer":"홍길동"
}
]
JavaScript
posts.forEach(post=>{
console.log(post.title);
});
Why Use JSON?
JSON is lightweight and easy to read.
Additionally, most programming languages support JSON,
JavaScript
PHP
Python
Java
C#
Node.js
making it easy to exchange data between them.
It's currently the most widely used method for data interchange.
Where Is JSON Used in Practice?
JSON is used in almost all web services.
For example:
Login systems
Forums and boards
E-commerce platforms
User management
Comments
Chat services
AI APIs
Map APIs
Weather APIs
Essentially, anywhere data is exchanged between client and server.
The Fetch API and AJAX covered in next week's lesson mostly handle JSON data.
Key Takeaways from This Lesson
Today we learned the basics of JSON and how to use it effectively.
Important points to remember:
JSON is a standard format for exchanging data.
JSON resembles JavaScript objects closely.
In JSON, property names must be in double quotes.
JSON.parse()converts strings to objects.JSON.stringify()converts objects to strings.Forum listings and user information are typically processed as JSON.
The Fetch API and AJAX commonly use JSON.
Conclusion
JSON is a fundamental skill every web developer must know.
At first, it might be confusing because it resembles objects, but once you master converting between strings and objects, you can easily handle most data formats.
Practice using JSON.parse() and JSON.stringify() by running the examples from this lesson. This will help you understand Fetch API and AJAX in next week's lesson better.
In the following lesson, we'll learn about Fetch API and AJAX, which are used to exchange data between JavaScript and PHP for creating dynamic web pages.
FAQ
What does JSON stand for?
JSON stands for JavaScript Object Notation, a standard format for exchanging data in web applications.
Why must property names be in double quotes in JSON?
Unlike JavaScript objects where you can omit quotes around property names, JSON requires double quotes for all keys to maintain consistency across different programming languages and systems.
Korean Source
This article is an English localization of a Korean-language report from BlogScore. Original: [JS 강좌] 11강 - JSON 이해하기와 데이터 다루기