Quick answer

Responses can be truncated, contain BOM or extra bytes, or mix JSON with text.

API Malformed Response

Responses can be truncated, contain BOM or extra bytes, or mix JSON with text. Parsers need a single, complete JSON value.

Common causes

How to fix

API Malformed Response helps you identify responses that are truncated, broken, or not valid JSON. This usually happens when an API returns partial output, a UTF-8 BOM, extra bytes before or after the payload, HTML error text, or mixed content that prevents parsers from reading a single complete JSON value. Developers, QA teams, and integration engineers use this kind of check to diagnose parsing failures, protect downstream systems, and confirm that an endpoint is returning machine-readable data in the expected format.

How This Validator Works

This validator checks whether an API response can be interpreted as one complete JSON document. It looks for common structural problems such as missing braces, unfinished arrays, invalid quoting, stray characters, and non-JSON content wrapped around the payload. In many cases, malformed responses are caused by transport issues, server-side exceptions, proxy injection, or an endpoint returning HTML instead of JSON.

Common Validation Errors

Malformed API responses often fail for predictable reasons. A response may be cut off mid-object, contain a server error message appended to the JSON, or include formatting that is valid for humans but invalid for parsers. Even a single unexpected character can cause a strict JSON parser to reject the entire response.

Where This Validator Is Commonly Used

This check is useful anywhere JSON APIs are consumed by applications, scripts, or automation pipelines. It is especially helpful during development, API testing, incident response, and integration debugging when a client unexpectedly fails to parse a response.

Why Validation Matters

API validation helps ensure that systems receive data in a predictable format. When a response is malformed, downstream code may fail, retry unnecessarily, or process incomplete data. Validating response structure early can reduce debugging time, improve reliability, and make integration issues easier to isolate. It also supports safer automation by confirming that the payload is actually JSON before a parser or workflow depends on it.

Technical Details

JSON parsers generally expect a single complete value: an object, array, string, number, boolean, or null. For API responses, the most common expectation is a top-level object or array with no extra content outside the payload. If the response includes a UTF-8 BOM, partial transmission, compression corruption, or server-side debug output, strict parsers may reject it even if the content looks mostly correct.

Expected format One complete JSON value with valid syntax
Common parser behavior Rejects extra characters, incomplete structures, and invalid encoding
Typical sources REST APIs, webhook payloads, internal service responses, test fixtures
Related standards JSON syntax, UTF-8 encoding, HTTP response handling

FAQ

What does a malformed API response mean?

A malformed API response is a payload that cannot be parsed as valid JSON. This may happen when the response is incomplete, contains invalid syntax, or includes non-JSON content such as HTML or debug text. In practice, it means the client cannot reliably read the data until the response format is corrected.

Why would an API return truncated JSON?

Truncated JSON can occur if the connection drops, the server times out, a proxy interrupts the response, or the application crashes before finishing output. It can also happen when streaming or buffering is misconfigured. The result is a payload that starts correctly but ends before all braces or brackets are closed.

Can extra text before or after JSON break parsing?

Yes. Many parsers require the response body to contain only one JSON value. If the payload includes a warning banner, HTML error page, log line, or any other text outside the JSON structure, parsing may fail even if the JSON itself is otherwise valid. Strict validation helps catch this early.

Does a UTF-8 BOM cause JSON errors?

It can. Some parsers tolerate a BOM, while others reject it or treat it as unexpected bytes at the start of the response. If a response appears valid but still fails to parse, checking for encoding issues is a useful step. Ensuring clean UTF-8 output often resolves this class of problem.

How is malformed JSON different from invalid schema?

Malformed JSON is a syntax problem: the response cannot be parsed at all. Invalid schema means the JSON is syntactically correct but does not match the expected structure, fields, or data types. A parser may accept schema-invalid JSON, but an application can still fail if required keys are missing or incorrectly shaped.

What should I check first when an API response fails?

Start by confirming whether the response body is complete and contains only JSON. Then inspect the HTTP status code, content type, encoding, and any proxy or server logs. If the payload is truncated, look for timeout or transport issues. If it contains mixed content, identify where the extra output is being added.

Can HTML error pages be mistaken for JSON?

Yes. Some endpoints return an HTML error page when authentication fails, a route is missing, or the server encounters an exception. If a client expects JSON and receives HTML instead, parsing will usually fail immediately. Checking the response headers and raw body helps distinguish this from a JSON syntax problem.

Is a malformed response always caused by the API server?

Not always. The issue may originate from the server, but it can also be introduced by gateways, CDNs, reverse proxies, middleware, or client-side assumptions about the response format. Validation is useful because it helps narrow down whether the problem is in generation, transport, or consumption of the payload.

Related Validators & Checkers

FAQ

What is a BOM in JSON?
Byte Order Mark (e.g. EF BB BF) at the start of a file. Some parsers reject it; strip it before parsing.
Can response have multiple JSON objects?
Standard JSON is one value per document. NDJSON (newline-delimited) is one JSON per line; parse line by line.

Fix it now

Try in validator (prefill this example)

Related

All tools · Canonical