Blog post
JSON REST API Best Practices
Design better JSON REST APIs — naming conventions, error formats, versioning, pagination, and performance tips.
Shashank Jain
Author


Article
Response Envelope Structure
Consistent response shapes reduce client-side surprises. Pick a pattern and stick to it:
// Success
{
"data": { "id": 1, "name": "Alice" },
"meta": { "requestId": "abc123" }
}
// Error
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Email is required"
}
}Naming Conventions
| Element | Convention | Example |
|---|---|---|
| JSON keys | camelCase | firstName, createdAt |
| URL paths | kebab-case | /user-profiles |
| Timestamps | ISO 8601 | 2026-06-14T12:00:00Z |
| IDs | String (not int) | "id": "usr_abc123" |
HTTP Status Codes
| Code | Use case |
|---|---|
| 200 | GET, PUT success |
| 201 | POST created resource |
| 204 | DELETE success (no body) |
| 400 | Bad request / validation error |
| 401 | Not authenticated |
| 403 | Authenticated but not authorized |
| 404 | Resource not found |
| 422 | Unprocessable entity |
| 429 | Rate limited |
Pagination
// Cursor-based (recommended for large datasets)
{
"data": [...],
"meta": { "nextCursor": "abc", "hasMore": true }
}
// Offset-based
{
"data": [...],
"meta": { "total": 1250, "page": 3, "perPage": 20 }
}FAQ
Should JSON API keys use camelCase or snake_case?
camelCase is most common in REST APIs. Pick one and never mix conventions in the same API.
Should I always wrap responses in a data envelope?
Yes. A bare array response cannot be extended without breaking clients. An envelope lets you add metadata and pagination later.
How should I represent null vs missing fields?
Always include fields as null rather than omitting them. Omitted fields are ambiguous.
What Content-Type should JSON APIs use?
Use Content-Type: application/json for standard APIs.
How should I version my API?
URL versioning (/v1/users) is the most common and visible approach. Header versioning is cleaner but harder to test in a browser.
Keep reading
Recent blogs

Jun 14, 2026
JSON in C#: System.Text.Json and Newtonsoft Complete Guide
Serialize and deserialize JSON in C# using System.Text.Json and Newtonsoft.Json with practical examples.

Jun 14, 2026
JSON to Markdown Table: Convert JSON Arrays Instantly
Convert JSON arrays to Markdown tables in JavaScript, Python, and with the free online tool.

Jun 14, 2026
JSON in TypeScript: Type-Safe Parsing and Validation
Stop using any for JSON in TypeScript — use Zod, type guards, and generics for fully type-safe parsing.