Lesson 23 of 30

JSON

Chapter 23

JSON

Learn how JSON is used to exchange structured data in Node.js APIs.

Theory

JSON stands for JavaScript Object Notation. It is a lightweight text format used to represent structured data. JSON is commonly used in REST APIs because it is easy for applications to generate and parse. JSON supports values such as: • Strings • Numbers • Booleans • Arrays • Objects • null

Example

Node.js Example
const user = {
  name: "Alex",
  age: 25,
  skills: ["Node.js", "JavaScript"]
};

console.log(JSON.stringify(user));

Output

The JavaScript object is converted into a JSON string.

Practice

Create a JSON object representing a product with name, price, and category.

Interview Questions

1.

What is JSON?

2.

Why is JSON commonly used in REST APIs?

3.

What does JSON.stringify() do?

Quick Quiz

Which option best matches this chapter?

A.JavaScript Object Notation
B.Java Server Object Network
C.JavaScript Online Node
D.JSON Operating Network

Answer: JavaScript Object Notation