← Back to Blog
APIs

How JSON is Used in REST APIs

Published January 2026 • 6 min read

JSON and REST APIs go hand in hand. If you have ever called a web API using fetch(), Axios, or a library like requests in Python, you have almost certainly been sending and receiving JSON. Here is a practical look at how JSON flows through a REST API.

What is a REST API?

A REST (Representational State Transfer) API is a way for two systems to communicate over HTTP. The client sends requests to defined endpoints (URLs), and the server responds with data — typically formatted as JSON.

A Typical JSON API Response

Here is what a response from a user API endpoint might look like:

GET https://api.example.com/users/42

{
  "id": 42,
  "name": "Dinesh N.",
  "email": "dinesh@example.com",
  "role": "developer",
  "createdAt": "2024-03-15T10:30:00Z"
}

Sending JSON in a Request Body

When creating or updating resources, you send JSON in the request body:

POST https://api.example.com/users
Content-Type: application/json

{
  "name": "Priya Sharma",
  "email": "priya@example.com",
  "role": "editor"
}

The Content-Type: application/json header tells the server to expect a JSON body.

Handling Errors with JSON

Well-designed APIs also return errors as JSON, making them easy to handle programmatically:

{
  "error": {
    "code": 404,
    "message": "User not found",
    "details": "No user exists with id 99"
  }
}

Parsing JSON in JavaScript

In the browser or Node.js, parsing an API response is straightforward:

const response = await fetch('https://api.example.com/users/42');
const user = await response.json(); // Parses JSON automatically
console.log(user.name); // "Dinesh N."

Common JSON API Patterns

When debugging API responses, paste the raw JSON into the JSON Pretty formatter on this site to make it readable instantly.