Why this matters
An HTTP status code tells you whether the server considered the request successful, but it does not tell you whether the response body contains valid JSON. A server or proxy can return an HTML error page, login prompt, gateway notice, or application-generated error document with a 200 status. The request appears successful to many clients, yet any code attempting to parse the body as JSON fails.
JSON is stricter than it may appear. Object members and array elements must be separated by commas, object keys and string values must use straight double quotation marks, and the closing punctuation must match the opening punctuation. A trailing comma, a missing comma, or a typographic “smart quote” can make an otherwise familiar response impossible to parse. Valid JSON is also not necessarily the response the caller expected: it may contain an error object, an empty body, or a different data structure. The first question is therefore whether the body is syntactically JSON; only then is it useful to ask whether its contents are correct.
The process
- Preserve the raw response. Capture the exact body without allowing an editor, browser extension, log viewer, or chat interface to normalize it. In particular, keep the original quotation marks and punctuation until the defect has been identified. A formatter may make the problem easier to see, but it should not be treated as a repair mechanism.
- Open json-formatter and choose validate mode. The tool has three real modes: format, minify, and validate. Validation is the appropriate starting point because it addresses the central question directly: whether the pasted text can be parsed as JSON. The formatter also performs its processing locally in the browser according to its documented capabilities.
- Paste the response body into the formatter. Paste the text exactly as received, including any leading whitespace, HTML, or unusual quotation marks. Do not first convert the response into a JavaScript object or remove characters that look suspicious. That would hide the malformed bytes that the parser needs to see.
- Review the validation result. If parsing fails, json-formatter reports an error beginning with “Invalid JSON:”. Do not assume that the first visible punctuation mark is necessarily the only problem, and do not assume the error text identifies the exact character or line unless the tool actually shows that detail. Treat it as evidence that the body violates JSON syntax somewhere.
- Locate the specific failure pattern. Inspect the body for the common cases. A trailing comma appears immediately before a closing brace or bracket. A missing comma appears between two complete values, such as two adjacent object properties. A smart quote appears as a curled opening or closing quotation mark inside a key or string. If the body begins with a tag such as an HTML document or paragraph element, it is not JSON at all, even when its HTTP status was 200.
- Correct the source or create a corrected copy. Remove only the syntax that is actually invalid: add a missing separator, remove an extra separator, or replace typographic quotation marks with straight double quotes. If the body is an HTML error page, do not try to turn the tags into JSON. Inspect the server-side error instead, or confirm whether the endpoint returned the intended representation.
- Validate again, then use format mode if needed. Once the text passes validation, format mode can make the structure easier to inspect. This is useful for reading nested objects and arrays, but formatting is not a substitute for validation. Minify mode serves the opposite purpose: it removes whitespace from JSON that is already valid. Neither mode should be expected to turn malformed input into a trustworthy API response.
- Query valid JSON when you need to isolate a value. Open json-path-query, enter an expression in the field labeled JSONPath Expression, and place the JSON in the field labeled Paste your JSON. The tool also accepts .json files and supports drag-and-drop. A query can help you locate a particular field after syntax is sound, but it cannot extract data from a body that the JSON parser rejects. If the API returns a JWT rather than ordinary JSON, use jwt-decoder instead: its labeled sections are Header (Algorithm & Type), JWT Token, and Payload (Claims).
Worked example
Suppose an API response looks like this:
{
"id": 42,
"name": "Ada"
"roles": ["admin", "editor"]
}
The body is visually plausible, but there is no comma between the name and roles members. Pasting it into json-formatter and choosing validate mode causes an “Invalid JSON:” result because the parser cannot complete the object. Adding the missing comma produces valid JSON:
{
"id": 42,
"name": "Ada",
"roles": ["admin", "editor"]
}
Now suppose a later response contains a trailing comma:
{
"status": "ok",
}
That response also fails validation. The comma after the final member is not allowed in this JSON object, so removing it fixes the syntax. A third response may look valid until its quotation marks are examined closely:
{
"message": “Success”
}
The opening quotation mark before Success is a typographic quote rather than the required straight double quote. A parser will reject it. Replacing both smart quotes with straight quotes resolves this particular defect, provided there are no other syntax errors.
The most misleading case is different. A proxy might return a page beginning with <!DOCTYPE html> or <html>, while the HTTP response reports 200. Validation still fails because HTML is not JSON. Renaming the body to a .json file would not change its contents or make it valid. The real issue is that the endpoint returned the wrong representation. After the server is corrected, the JSON can be validated and queried. For example, in json-path-query, the expression $.roles[0] can isolate the first role from the corrected object.
Common mistakes
- Treating HTTP 200 as proof that the body is JSON. A successful status only describes the HTTP exchange. The body can still be an HTML page or another non-JSON representation, and the formatter will reject it just as it rejects syntactically broken JSON.
- Assuming a formatter automatically repairs invalid JSON. Formatting changes the presentation of valid JSON; it does not establish that malformed input is safe to use. A trailing comma or missing comma remains a syntax error, and minifying the text cannot fix either one.
- Using a formatter as a schema validator. Passing the parse check means only that the text is valid JSON syntax. It does not prove that required fields exist, that field types are appropriate, or that the values match what the endpoint promised.
- Deleting punctuation until validation happens to pass. This can change the meaning of the payload. For example, removing an entire property may conceal the real server defect, while adding a comma in the wrong location can create a different but still invalid structure.
- Overlooking typographic quotation marks. Keys copied from word processors, documentation, or presentation material can contain curly quotes. They look like quotation marks on screen but are not the double-quote character required by JSON string syntax.
- Uploading an HTML response merely because it arrived with JSON in the request. json-formatter accepts .json files, but the extension does not convert HTML into JSON. An HTML body must be recognized as the wrong response type rather than cosmetically edited.
- Confusing malformed JSON with a malformed JSONPath expression. json-path-query has separate errors for invalid JSONPath syntax. An “Invalid JSONPath expression” message concerns the query, while a parsing failure in the pasted document means the JSON itself must be fixed first.
- Using jwt-decoder for every API response. jwt-decoder is specialized for a JWT with three dot-separated parts. It is appropriate when the endpoint returns a token, not when it returns a normal JSON object or an HTML error page.
Limitations of this approach
- The browser tools do not diagnose the HTTP exchange. They can analyze a body you provide, but they do not establish why the server returned that body or whether its status and headers were appropriate. An HTML body with a 200 status still requires investigation at the server, proxy, authentication, or routing layer.
- Syntax validity is not semantic correctness. A response can parse successfully while containing an error code, stale data, null values, or a different object shape. Contract or schema validation is needed when the API has a defined model, but that capability is not established by these tools.
- JSONPath is downstream of parsing. json-path-query is useful for navigating valid JSON and selecting fields. It cannot reliably query a malformed document, so validation must come first.
- The file-oriented workflow does not fit every error response. json-formatter accepts .json files, while an HTML error page is not JSON and may not be accepted as the expected file type. Pasting the raw body is the more generally useful route when the response is plainly not JSON.
- JWT decoding is not token verification. jwt-decoder can parse a token’s structure and claims, and it reports malformed token formats or claim parsing failures. The tool does not establish cryptographic signature verification, so decoding alone should not be treated as proof that a token is authentic.
- Correcting the pasted copy may conceal a production defect. A local correction can help you inspect the intended structure, but the malformed response remains a server-side problem. The endpoint should eventually return valid JSON with the expected representation and status.
Frequently asked questions
What is the safest way to test an API response? Validate the raw body before formatting or querying it. This keeps syntax errors visible and prevents you from accidentally changing the evidence while trying to clean it up.
Does a trailing comma make JSON invalid? Yes. A comma cannot immediately precede the closing brace of an object or the closing bracket of an array. Removing that extra comma is the appropriate correction when no other defect is present.
Can a missing comma be easy to miss? Yes, especially in a one-line payload or when a long value ends next to another key. A visual formatter can expose the boundary between members, but validation is what confirms whether the JSON parser accepts the complete result.
Why does an HTML page fail even when the server returns 200? HTTP status and content syntax are separate concerns. A 200 response can contain HTML, but HTML is not a valid JSON document. The formatter correctly treats the body as invalid JSON, and the endpoint or intermediary still needs to be checked.
Are straight and smart quotation marks interchangeable in JSON? No. JSON string delimiters require the straight double-quote character. Smart quotes must be replaced, along with any other malformed characters found during validation.
Once the response validates, should I use format or minify? Use format when you need to inspect the structure. Use minify when you need a compact representation of JSON that already parses correctly. Neither mode establishes that the payload satisfies an API contract.
Can json-path-query tell me which line of malformed JSON is wrong? Its documented errors distinguish problems with the JSONPath expression from failures while processing input, but the tool do not promise line-level diagnostics. Fix JSON syntax with json-formatter first, then use JSONPath to select the fields you need.
When should I use jwt-decoder? Use it when the response contains a JWT rather than an ordinary JSON document. It exposes the Header (Algorithm & Type), Payload (Claims), and token structure, while reporting malformed formats. It is not a general-purpose JSON validator or a substitute for cryptographic token verification.