Quick answer

Many APIs return JSON.

API Response Invalid JSON

Many APIs return JSON. If the response body is not valid JSON (e.g. truncated, malformed, or HTML error page), parsers will fail. Use a checker to get the exact line and column.

Common causes

How to fix

Examples

Bad

{"id": 1, "name": "test",}

Good

{"id": 1, "name": "test"}

API response bodies need to be valid JSON for clients, SDKs, and automation to parse them reliably. This checker helps identify responses that are truncated, malformed, wrapped in HTML, or otherwise not valid JSON, so you can pinpoint where parsing fails and correct the source. It is useful for backend developers, API integrators, QA teams, and support engineers troubleshooting broken integrations, unexpected 500 pages, or inconsistent response formats. When an endpoint is supposed to return JSON but does not, downstream systems may fail silently or throw parse errors. Validating the response body early helps isolate whether the issue is in the API server, gateway, proxy, or client handling.

How This Validator Works

This validator checks whether the response body can be parsed as valid JSON according to standard JSON syntax rules. It looks for common structural issues such as missing commas, unclosed brackets, invalid quotes, trailing characters, and incomplete payloads. If the response is not JSON at all, the tool can help reveal that the server returned HTML, plain text, or an error page instead of the expected API payload.

Common Validation Errors

Where This Validator Is Commonly Used

Why Validation Matters

JSON is a common interchange format because it is lightweight, predictable, and easy to parse across programming languages. When an API response is invalid, clients may fail to load data, retry unnecessarily, or surface hard-to-read errors. Validating response bodies helps teams catch formatting problems before they reach production users, and it improves reliability across services that depend on structured data. It also makes it easier to separate content issues from transport issues such as HTTP status codes, caching, or proxy behavior.

Technical Details

FAQ

What does “invalid JSON” mean in an API response?

It means the response body does not follow JSON syntax rules, so a parser cannot read it correctly. This can happen when the payload is truncated, contains missing punctuation, uses single quotes, or includes HTML or plain text instead of structured data. The issue is in the body content, not necessarily the HTTP status code.

Why would an API return HTML instead of JSON?

That often happens when an endpoint errors before reaching the JSON serializer, or when a proxy, load balancer, or authentication layer returns its own page. Common examples include login redirects, 404 pages, and server error templates. Even if the endpoint is intended to serve JSON, upstream systems can change the actual response body.

How can I find the exact JSON error location?

Most parsers report a line and column number where parsing failed. Start there and inspect the surrounding characters for missing commas, quotes, or closing brackets. If the response is minified, formatting it first can make the error easier to spot. If the body is truncated, compare the end of the payload with the expected structure.

Can a response be valid JSON but still break my app?

Yes. A response can be syntactically valid JSON and still be wrong for your application if the schema, field names, or data types do not match what the client expects. For example, a string may be returned where an object is expected. This validator checks syntax, while schema validation checks structure and meaning.

Does the Content-Type header affect JSON parsing?

It can affect how clients decide whether to parse the body as JSON, but it does not change the actual syntax of the payload. A response with the wrong header may still contain valid JSON, while a response with the correct header may still be malformed. Both the header and the body should be checked during debugging.

What are the most common JSON formatting mistakes?

Frequent mistakes include missing commas, unescaped quotation marks, trailing commas, unclosed braces, and single quotes around strings. Another common issue is appending debug output or stack traces after the JSON object. These problems are easy to miss when responses are generated dynamically or assembled from multiple sources.

How do proxies or gateways cause invalid JSON?

Proxies and gateways may rewrite responses, inject error pages, or cut off payloads if timeouts occur. They can also alter headers or compress data incorrectly. If the origin server returns valid JSON but the final response is invalid, the issue may be introduced somewhere between the application and the client.

Should I validate API responses in development and production?

Yes. In development, validation helps catch formatting bugs early. In production, it helps diagnose intermittent issues caused by timeouts, upstream failures, or misconfigured middleware. Many teams validate responses in automated tests, monitoring, and incident response workflows to reduce integration failures.

Related Validators & Checkers

FAQ

Why is my API response not valid JSON?
Often the server returned HTML (error page), or the body was truncated. Validate the raw body to see the exact error.
Can I paste a full HTTP response?
Yes. The checker extracts the body after the blank line and validates the JSON part.

Fix it now

Try in validator (prefill this example)

Related

All tools · Canonical