Loading Depth Study
Preparing your workspace
JSON is a common data format used between frontend applications and backend services.
Modern APIs commonly send and receive JSON. A backend needs to parse incoming JSON request bodies and return properly formatted JSON responses. Data should be validated before it is used because clients can send incorrect or unexpected values. Responses should also use meaningful status codes and consistent structures so frontend clients can handle them predictably.
A React application may send a JSON request containing a student's course enrollment information to a Node.js backend.
const payload = {
studentId: 'u101',
courseId: 'c201'
};
const json = JSON.stringify(payload);
console.log(json);
const parsed = JSON.parse(json);
console.log(parsed.courseId);The first log prints JSON text and the second prints the course ID from the parsed object.