API JSON best practices

API JSON best practices

Consistent JSON makes APIs easier to use, document, and debug. Here are practices that improve developer experience.

1) Choose a naming convention and stick to it

Mixing styles inside the same API is a frequent source of bugs.

2) Be intentional with null vs missing

3) Use stable IDs and explicit types

IDs are commonly strings even if they look numeric (to avoid precision and formatting issues across systems).

4) Pagination should be predictable

Common patterns include:

{
  "items": [/* ... */],
  "nextCursor": "abc123"
}

5) Standardize error shapes

Clients should branch on stable error codes. See: API error payload patterns.

6) Version carefully

Related: JSON Schema basics · Validate JSON