JSON in APIs

View saved

JSON is the common body format

Most REST APIs use application/json for request and response bodies.

{
  "title": "Practical APIs",
  "year": 2026,
  "tags": ["http", "json"]
}

Set Content-Type

Clients and servers should declare JSON explicitly.

Content-Type: application/json

Keep shapes predictable

Use consistent field names, avoid mixing arrays and objects for the same field, and document nullability.

Errors as JSON too

Return a stable error object so clients can show messages or codes.

{
  "error": "validation_failed",
  "details": [{ "field": "year", "message": "must be an integer" }]
}

Comments

One comment per signed-in account. Comments are saved with this page’s URL.