Practical examples of JSON for RESTful API communication examples
Real-world examples of JSON for RESTful API communication examples
Let’s start with what you actually care about: concrete payloads you can copy, tweak, and ship. These examples of JSON for RESTful API communication examples focus on the patterns you’ll reuse over and over.
1. User registration and authentication JSON example
User sign-up and login flows are among the best examples of JSON for RESTful API communication. A typical client sends a POST request to create a new user:
POST /api/v1/users HTTP/1.1
Content-Type: application/json
Authorization: Bearer <admin-token>
{
"email": "alex.smith@example.com",
"password": "S3cureP@ssw0rd",
"first_name": "Alex",
"last_name": "Smith",
"marketing_opt_in": true
}
A clean JSON response might look like:
{
"id": "usr_92f3b8c1",
"email": "alex.smith@example.com",
"first_name": "Alex",
"last_name": "Smith",
"created_at": "2025-01-10T18:42:13Z",
"status": "active"
}
Notice what’s missing: the password. Examples include only what the client needs. In 2024–2025, most production APIs avoid returning sensitive fields and instead rely on short-lived access tokens (JWTs or opaque tokens) for follow-up requests.
For login, an example of a JSON-based authentication request:
POST /api/v1/auth/login
Content-Type: application/json
{
"email": "alex.smith@example.com",
"password": "S3cureP@ssw0rd"
}
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"user": {
"id": "usr_92f3b8c1",
"email": "alex.smith@example.com"
}
}
These are simple, but they’re still among the best examples of JSON for RESTful API communication examples you’ll use daily.
2. E‑commerce order: nested JSON with arrays
When people ask for real examples of JSON for RESTful API communication examples, e‑commerce payloads are usually near the top of the list because they show nested structures and arrays.
POST /api/v1/orders
Content-Type: application/json
Authorization: Bearer <token>
{
"customer_id": "cus_1039",
"currency": "USD",
"items": [
{
"product_id": "prod_501",
"name": "Noise-Canceling Headphones",
"quantity": 1,
"unit_price": 199.99
},
{
"product_id": "prod_782",
"name": "USB-C Charging Cable",
"quantity": 2,
"unit_price": 9.99
}
],
"shipping_address": {
"line1": "123 Market St",
"city": "San Francisco",
"state": "CA",
"postal_code": "94103",
"country": "US"
},
"metadata": {
"source": "mobile_app",
"campaign": "spring_promo_2025"
}
}
A typical JSON response might normalize some values and add server-calculated fields:
{
"id": "ord_7f29b3",
"customer_id": "cus_1039",
"status": "processing",
"currency": "USD",
"subtotal": 219.97,
"tax": 19.80,
"shipping": 0,
"total": 239.77,
"items": [
{
"product_id": "prod_501",
"quantity": 1,
"unit_price": 199.99
},
{
"product_id": "prod_782",
"quantity": 2,
"unit_price": 9.99
}
],
"created_at": "2025-02-01T15:12:44Z"
}
This example of JSON shows how arrays, nested objects, and metadata all live comfortably in a RESTful design.
3. Filtering, sorting, and pagination with JSON
Modern APIs rarely return “everything.” Instead, they paginate and let clients filter and sort. These are underrated examples of JSON for RESTful API communication examples because they show how your API scales.
A client might request a page of users:
GET /api/v1/users?limit=25&offset=50&sort=created_at&order=desc
Accept: application/json
A JSON response could be:
{
"data": [
{
"id": "usr_120",
"email": "user120@example.com",
"created_at": "2025-01-18T10:00:00Z"
},
{
"id": "usr_119",
"email": "user119@example.com",
"created_at": "2025-01-17T09:30:00Z"
}
],
"pagination": {
"limit": 25,
"offset": 50,
"total": 3200,
"next": "/api/v1/users?limit=25&offset=75&sort=created_at&order=desc",
"prev": "/api/v1/users?limit=25&offset=25&sort=created_at&order=desc"
}
}
Some APIs prefer cursor-based pagination for performance and reliability at scale:
{
"data": [ /* ...items... */ ],
"pagination": {
"cursor": "eyJpZCI6ICJ1c3JfMTIwIn0=",
"has_next": true
}
}
When you look at public APIs from large platforms in 2024–2025, examples include both offset and cursor approaches, but JSON remains the common language.
4. Error handling: JSON error formats that actually help
One of the best examples of JSON for RESTful API communication examples is a clear, structured error response. The goal is to make debugging easy for developers and safe for users.
Consider a failed validation during user creation:
POST /api/v1/users
Content-Type: application/json
{
"email": "not-an-email",
"password": "123"
}
A useful JSON error might be:
{
"error": {
"code": "validation_error",
"message": "One or more fields failed validation.",
"details": [
{
"field": "email",
"issue": "invalid_format",
"message": "Email must be a valid email address."
},
{
"field": "password",
"issue": "too_short",
"min_length": 8,
"message": "Password must be at least 8 characters long."
}
],
"request_id": "req_0e3c8d"
}
}
Notice the pattern: a top-level error object, a machine-readable code, a human-readable message, and structured details. This structure shows up in many real examples of JSON for RESTful API communication examples because it works well with logging, metrics, and client-side error handling.
For inspiration, many teams borrow ideas from the standardized problem details format described in RFC 7807, even if they don’t implement it exactly.
5. Partial updates with PATCH and JSON
APIs in 2024–2025 increasingly favor partial updates to avoid sending entire objects. Here’s an example of updating only a user’s profile fields:
PATCH /api/v1/users/usr_92f3b8c1
Content-Type: application/json
Authorization: Bearer <token>
{
"first_name": "Alexander",
"marketing_opt_in": false
}
A typical response echoes the updated resource:
{
"id": "usr_92f3b8c1",
"email": "alex.smith@example.com",
"first_name": "Alexander",
"last_name": "Smith",
"marketing_opt_in": false,
"updated_at": "2025-02-02T09:15:00Z"
}
This example of JSON shows how RESTful APIs can stay efficient on mobile networks and in microservice environments where bandwidth and latency still matter.
6. JSON in healthcare and education APIs
If you work with regulated domains, you’ll see even more structured examples of JSON for RESTful API communication examples.
Healthcare-style JSON example
Public health and research APIs often use JSON to share aggregate data. For instance, a hypothetical endpoint returning weekly case counts might respond like this:
GET /api/v1/covid/cases?state=CA&week=2025-W03
Accept: application/json
{
"state": "CA",
"week": "2025-W03",
"cases": 15234,
"deaths": 122,
"hospitalizations": 874,
"source": "CDC",
"last_updated": "2025-01-25T12:00:00Z"
}
While this is fictional, it mirrors patterns you’ll see in real public health APIs and data downloads from sites like the Centers for Disease Control and Prevention. The point is that even highly regulated sectors lean heavily on JSON for RESTful communication.
Education-style JSON example
Education platforms use JSON to sync student progress between learning management systems (LMS), assessment tools, and analytics dashboards. A typical payload might look like:
{
"student_id": "stu_4412",
"course_id": "cs101",
"module_id": "mod_3",
"score": 88,
"completed_at": "2025-02-03T16:30:00Z",
"metadata": {
"attempt": 2,
"delivery_mode": "online"
}
}
Standards like IMS Global’s specifications and modern LMS APIs increasingly provide JSON endpoints, even when older systems still speak XML. Universities and online programs documented on sites like Harvard University often highlight API-based integrations that rely on JSON behind the scenes.
7. JSON in microservices and internal APIs
So far, the examples of JSON for RESTful API communication examples have focused on public-facing APIs. Inside your infrastructure, microservices also talk JSON to each other because it’s easy to debug and language-agnostic.
Imagine a billing service calling an internal inventory service:
GET http://inventory.internal/api/v1/stock?product_id=prod_501
Accept: application/json
{
"product_id": "prod_501",
"available": 37,
"reserved": 5,
"warehouse": "west-coast-1",
"updated_at": "2025-02-02T11:00:00Z"
}
The billing service may then send a JSON message to a notification service when an order ships:
{
"event": "order_shipped",
"order_id": "ord_7f29b3",
"customer_id": "cus_1039",
"shipped_at": "2025-02-02T14:22:10Z",
"carrier": "UPS",
"tracking_number": "1Z999AA10123456784"
}
Even when the transport isn’t HTTP (for example, messaging queues like Kafka or RabbitMQ), the payloads are still often JSON because it’s easy to log and inspect.
8. JSON vs XML in RESTful APIs (2024–2025 reality check)
You can’t talk about examples of JSON for RESTful API communication examples without acknowledging XML. XML still shows up in legacy enterprise systems, older SOAP services, and some standards-heavy domains. But the trend is clear: most new RESTful APIs default to JSON.
Why JSON keeps winning in 2024–2025:
- Native support in JavaScript and broad support across modern languages
- Smaller payloads compared to verbose XML
- Easier to read and write for humans
- Straightforward mapping to objects and collections
XML still has its place for document-centric data or when schemas like XSD are deeply embedded in an ecosystem. You still see XML in some healthcare messaging standards and older financial integrations. But when big tech companies publish public REST APIs, the best examples almost always use JSON first, with XML (if offered at all) as a secondary option.
For real-world context on how data formats matter in health and research APIs, you can explore resources from the National Institutes of Health, where many projects now expose JSON-based endpoints alongside older formats.
Best practices shown in these JSON REST examples
Looking across all these examples of JSON for RESTful API communication examples, a few patterns keep showing up:
- Consistent naming: Pick
snake_caseorcamelCaseand stick with it. - Timestamps in ISO 8601: Use UTC and ISO 8601 strings like
2025-02-02T14:22:10Z. - Predictable envelopes: Wrap results in
data,pagination, orerrorobjects so clients know where to look. - Clear error codes: Combine human-readable messages with machine-readable
codevalues. - Minimal exposure of sensitive data: Never return passwords, secrets, or internal IDs that don’t need to be public.
- Versioning: Use versioned paths (like
/api/v1/) or headers so you can evolve your JSON format without breaking clients.
These aren’t just theory. When you explore public API docs from payment processors, social platforms, or healthcare data providers, the best examples follow these same patterns.
FAQ: examples of JSON for RESTful API communication examples
Q1. What are some common examples of JSON for RESTful API communication examples?
Common examples include user registration and login payloads, e‑commerce orders with nested items, paginated lists of resources, structured error responses, partial updates with PATCH, and domain-specific payloads in healthcare and education APIs.
Q2. Can you show an example of a simple JSON GET response in a REST API?
A very simple example of a JSON response might look like this:
{
"id": 1,
"title": "Hello, world",
"published": true
}
This kind of response is typical for blog posts, tasks, notes, or any small resource in a RESTful service.
Q3. When should I choose JSON over XML for a RESTful API?
For most new APIs, JSON is the default choice because client libraries, browsers, and mobile SDKs handle it directly. XML is still used when you’re integrating with older systems that expect it or when specific industry standards require XML. In modern public APIs, real examples almost always favor JSON, with XML available only for backward compatibility.
Q4. How do I handle errors in JSON for RESTful APIs?
Return a standard HTTP status code (like 400, 401, 404, or 500) and a JSON body with an error object containing a code, message, and optional details. This pattern makes logs easier to search and clients easier to maintain.
Q5. Are there security concerns specific to JSON in RESTful communication?
Yes. You still need to validate and sanitize all inputs, enforce authentication and authorization, and avoid leaking sensitive data in JSON responses. You should also consider rate limiting and logging. Many security guidelines published by organizations like the U.S. government’s cybersecurity resources apply directly to JSON-based REST APIs.
Related Topics
Real‑world examples of best practices for using XML in APIs
Practical examples of parsing XML data in programming languages
Practical examples of parsing JSON data in programming languages
Real‑world examples of XML API security considerations in 2025
Practical examples of JSON for RESTful API communication examples
Modern examples of best practices for JSON in APIs
Explore More Data Formats: JSON vs XML in APIs
Discover more examples and insights in this category.
View All Data Formats: JSON vs XML in APIs