When an API response arrives as one long line or fails with an unhelpful parse error, a disciplined JSON workflow can reveal the problem quickly. This guide shows how to format minified JSON, validate syntax and structure, compare payloads, repair common errors, and use online tools safely without exposing sensitive data.
Overview
JSON is designed to be easy for machines to exchange, but payloads are not always easy for people to inspect. An API client may display a compact response, a configuration file may contain deeply nested objects, or a small punctuation mistake may prevent an entire request from being parsed. A JSON formatter improves readability; a JSON validator checks whether the text follows JSON syntax; schema validation checks whether the data has the required shape and types.
These are related but different tasks. Valid JSON can still be unsuitable for an API. For example, this payload is syntactically valid:
{"userId":"42","enabled":"true"}
However, an API that expects userId to be a number and enabled to be a Boolean may reject it. Formatting helps you see the values clearly, while schema or application-level validation identifies the type mismatch.
A reliable workflow is therefore:
- Preserve the original payload.
- Format it for inspection.
- Validate JSON syntax.
- Check the expected schema and business rules.
- Compare it with a known-good request or response.
- Retest the smallest possible change.
Checklist by scenario
When JSON is minified or difficult to read
- Copy the payload into a trusted editor or JSON formatter.
- Choose pretty-print or formatted output rather than editing the compact text directly.
- Confirm that the formatter reports valid JSON instead of silently changing it.
- Expand nested objects and arrays one level at a time.
- Look for unexpected nulls, empty arrays, duplicate-looking fields, and incorrect value types.
- Keep the original response available so you can verify that no data was lost.
For small, non-sensitive samples, a format JSON online tool can be convenient. For production payloads, use a local editor or a self-hosted utility when the data includes credentials, personal information, private URLs, internal identifiers, or customer records.
When a JSON syntax error is reported
Start near the character position or line number in the error message, but do not assume that position is the exact cause. Parsers often detect a problem at the point where the structure becomes impossible, which can be after the original mistake.
- Format the payload if possible; indentation makes the structure easier to follow.
- Inspect the line before the reported location.
- Check matching braces
{}and brackets[]. - Check that object keys use double quotes.
- Check commas between properties and array items.
- Remove comments, trailing commas, and unsupported expressions.
- Validate again after making one focused correction.
When validating a nested API response
Syntax validation is only the first checkpoint. Compare the payload against the API contract, documentation, or an OpenAPI definition. Confirm the expected path, such as data.items[0].id, and verify whether fields are required, nullable, read-only, or conditionally present.
Check the following:
- Object versus array:
{}and[]are not interchangeable. - Type consistency: a string containing a number is not necessarily a number.
- Required fields: a valid JSON document can still omit required properties.
- Nullability:
nullmay have a different meaning from an empty string or missing field. - Dates and identifiers: confirm the API's expected representation rather than guessing.
- Additional properties: determine whether unknown fields are ignored or rejected.
For contract-focused testing, the OpenAPI contract testing guide provides a useful next step after basic JSON validation.
When comparing two payloads
- Format both documents using the same indentation and ordering rules.
- Use a structural or JSON-aware diff when available.
- Separate meaningful changes from formatting changes.
- Check additions, removals, changed types, and changed array order.
- Redact secrets before pasting either document into a comparison tool.
Do not rely only on visual comparison for large nested objects. A field moved to another level, an array item removed, or a Boolean changed to a string can be easy to miss in raw text.
What to double-check
| Symptom | Likely cause | What to inspect |
|---|---|---|
| Unexpected token or parse error | Missing comma, quote, brace, or bracket | The reported location and the preceding property or item |
| Invalid character | Single quotes, comments, smart quotes, or pasted markup | Whether the document contains strict JSON rather than JavaScript-like syntax |
| Trailing comma error | Comma after the final property or array item | The closing line before } or ] |
| Valid JSON but rejected request | Schema, type, authentication, or business-rule failure | API documentation, status code, response body, and request headers |
| Values appear to disappear | Incorrect repair, duplicate keys, or an editor transformation | The original payload and the formatted output side by side |
Strict JSON uses double-quoted strings and property names. It supports strings, numbers, objects, arrays, true, false, and null. It does not support comments, variables, functions, or trailing commas. A JavaScript object literal may look similar while still requiring changes before it can be sent as JSON.
Consider this invalid example:
{
"name": "Ada",
"roles": ["admin", "editor",],
}
The repaired version removes the trailing commas:
{
"name": "Ada",
"roles": ["admin", "editor"]
}
Repair only what you can explain. If a value is unclear, do not replace it with an empty string or null simply to make the validator pass. That may hide the original data-quality problem.
Common mistakes
- Confusing formatting with validation. Indentation changes presentation; it does not prove that the payload satisfies an API contract.
- Editing the only copy. Always retain the raw response or commit a configuration change before repairing it.
- Using single quotes. JSON requires double quotes for strings and object keys.
- Leaving comments in a request body. Comments may work in a configuration format or programming language but are not part of strict JSON.
- Ignoring types. The values
100,"100", andnullcan produce different application behavior. - Trusting an online tool with secrets. Remove authorization tokens, API keys, cookies, personal data, and production records before using a browser-based formatter or diff tool.
- Assuming every parser behaves identically. Tools may offer permissive modes, JSON5 support, comments, or automatic repair. Confirm that the final output is strict JSON when the receiving API requires it.
- Comparing minified text directly. Format both inputs first, then use a structural comparison where possible.
If the JSON error is part of a larger browser or API issue, inspect the request payload, response, status code, and network timing together. The frontend debugging checklist can help organize that broader investigation.
When to revisit
Return to this checklist whenever an API response fails validation, a configuration file becomes difficult to inspect, or a payload changes between environments. It is especially useful before a release, after an API version change, and when a team introduces a new formatter, editor extension, API client, or schema-validation step.
Before acting on a suspicious payload, use this short routine:
- Save an untouched copy and record where it came from.
- Remove or mask sensitive values.
- Format the redacted sample.
- Validate strict JSON syntax.
- Check the schema, types, required fields, and nesting.
- Compare it with a known-good payload.
- Make one documented change and retest.
- Keep the final payload and the reason for the change in version control or the relevant ticket.
Tool capabilities and API contracts can change, so review this workflow when your development process changes and periodically confirm that formatter settings, validation rules, and redaction practices still match the data you handle. For related debugging work, see the guides to SQL query formatting and JWT debugging and validation.