JSON Best Practices
Use camelCase for keys in JavaScript contexts, ISO 8601 for dates, and validate schema on both client and server.
Use camelCase for keys in JavaScript contexts, ISO 8601 for dates, and validate schema on both client and server.
// Good JSON API response structure
{
"data": {
"id": 1,
"userName": "alice", // camelCase
"createdAt": "2024-06-15T10:30:00Z" // ISO 8601
},
"meta": {
"total": 100,
"page": 1,
"perPage": 20
},
"errors": null
}
// Consistent error format
{
"errors": [
{ "field": "email", "message": "Invalid email address" }
]
}
Establish a consistent JSON response envelope (data, meta, errors) across all API endpoints for predictable handling.
More in JavaScript