Skip to main content

invalid_json

HTTP Status: 400 Bad Request

Example response

{
  "error": {
    "code": "invalid_json",
    "message": "Request body contains invalid JSON",
    "docs_url": "https://docs.vatly.dev/errors/invalid_json"
  },
  "meta": {
    "request_id": "550e8400-e29b-41d4-a716-446655440000"
  }
}

What happened?

The request body could not be parsed as valid JSON. This happens when:
  • The JSON syntax is malformed (missing quotes, trailing commas, unescaped characters)
  • The request body is empty when JSON was expected
  • The body contains non-JSON content (e.g. form-encoded data)

How to fix

  1. Validate your JSON: Use a JSON linter or JSON.parse() locally before sending
  2. Set the Content-Type header: Include Content-Type: application/json
  3. Check for trailing commas: JSON does not allow trailing commas after the last element
# Correct
curl -X POST https://api.vatly.dev/v1/validate/batch \
  -H "Authorization: Bearer vtly_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"vat_numbers": ["NL123456789B01"]}'

# Wrong - trailing comma
curl -X POST https://api.vatly.dev/v1/validate/batch \
  -H "Authorization: Bearer vtly_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"vat_numbers": ["NL123456789B01",]}'

Common mistakes

  • Trailing commas: ["a", "b",] is invalid JSON
  • Single quotes: JSON requires double quotes. {'key': 'value'} is invalid
  • Unescaped characters: Special characters in strings must be escaped
  • Empty body: Sending a POST with no body when JSON is expected