Guide

Validate JSON Before API Requests

A quick validation pass before sending an API request can separate JSON syntax problems from authentication, schema, and backend errors.

Why validate before sending

When an API request fails, the error message may point to authentication, permissions, schema validation, or malformed JSON. Validating the JSON body first removes one entire class of failures before the request reaches the server. It also makes copied cURL commands, Postman bodies, webhook samples, and integration tests easier to review.

Syntax checks to run

A strict JSON validation pass should confirm that the body parses as JSON and that the formatted output matches what you intended to send.

  • Every string and object key uses double quotes
  • There are no comments or trailing commas
  • Booleans are true or false, not True or False
  • Missing values are null or omitted, not undefined
  • The top-level value matches the endpoint expectation

Headers still matter

A valid JSON body can still fail if the request does not declare the right content type. For most JSON APIs, send Content-Type: application/json. If the endpoint also checks accepted response formats, include Accept: application/json so client and server agree on the payload format.

Broken request body

{ userId: 42, active: True, tags: ['beta',], }

Fixed request body

{ "userId": 42, "active": true, "tags": ["beta"] }

After syntax validation

Syntax validation only proves that the document is parseable. For production requests, also check the schema: required fields, unknown fields, value types, array lengths, enum values, date strings, and whether numeric identifiers should be numbers or strings.

Debugging tip

If a server still rejects valid JSON, compare the formatted request body against a known-good example. Semantic JSON diffing helps find real value changes while ignoring object key order, which is especially useful when payloads are generated by different tools.