> ## Documentation Index
> Fetch the complete documentation index at: https://docs.avatcado.com/llms.txt
> Use this file to discover all available pages before exploring further.

# invalid_json

> Error: request body contains malformed JSON

# invalid\_json

<Info>HTTP Status: **400 Bad Request**</Info>

## Example response

```json theme={null}
{
  "error": {
    "code": "invalid_json",
    "message": "Request body contains invalid JSON",
    "docs_url": "https://docs.avatcado.com/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

```bash theme={null}
# Correct
curl -X POST https://api.avatcado.com/v1/validate/batch \
  -H "Authorization: Bearer avat_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"vat_numbers": ["NL123456789B01"]}'

# Wrong - trailing comma
curl -X POST https://api.avatcado.com/v1/validate/batch \
  -H "Authorization: Bearer avat_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

## Catching this error with the SDKs

<CodeGroup>
  ```typescript @avatcado/node theme={null}
  import Avatcado, { ValidationError } from '@avatcado/node';

  const avatcado = new Avatcado('avat_live_your_api_key');
  const { data, error } = await avatcado.vat.validate({ vatNumber: '...' });

  if (error instanceof ValidationError) {
    console.log(error.message);
    console.log(error.details); // Array<{ field, message }> | null
  }
  ```

  ```python Python theme={null}
  from avatcado import Avatcado, ValidationError

  avatcado = Avatcado("avat_live_your_api_key")

  try:
      result = avatcado.vat.validate("...")
  except ValidationError as e:
      print(e.message)
      print(e.details)  # list of dicts or None
  ```
</CodeGroup>

## Related errors

* [`validation_error`](/errors/validation_error) - JSON is valid but fails schema validation
