When an API rejects a request or a fixture will not load, the problem is often not the data itself but its JSON syntax or structure. This practical checklist shows how to use a JSON formatter and validator, locate syntax errors, inspect escaping and types, and compare JSON documents so you can distinguish invalid JSON from a valid payload that simply does not match what the API expects.
Overview
JSON is a text format built from a small set of values: objects, arrays, strings, numbers, booleans, and null. Its simplicity makes it common in browser applications, configuration files, test fixtures, and API requests. It also means that one misplaced comma, unescaped quote, or unexpected array can stop a parser before your application receives any useful data.
A JSON formatter or JSON validator online can help with the first stage of diagnosis: confirming whether the text is syntactically valid and making its nesting easier to read. Formatting does not, however, prove that the document matches an API contract. A payload can be valid JSON and still contain the wrong property name, data type, nesting level, or required field.
Use this workflow:
- Save or copy the exact input, including the character position reported by the application.
- Validate the raw text before changing it.
- Format the valid document to expose its hierarchy.
- Compare the actual payload with a known-good example or schema.
- Test the smallest failing case and then restore fields one at a time.
For related debugging work, a structured text diff workflow can help compare API responses and configuration files. JSON-aware comparison is preferable when property order should not be treated as a meaningful difference.
JSON syntax reference
| Value | Valid example | Frequent issue |
|---|---|---|
| Object | {"id": 42} | Missing colon, quote, or closing brace |
| Array | ["draft", "published"] | Trailing comma or mixed structure |
| String | "hello" | Unescaped quote or line break |
| Number | 12.5 | Using a non-JSON numeric form or wrong type |
| Boolean | true or false | Writing True, FALSE, or a quoted value |
| Null | null | Confusing null with an empty string or missing field |
Object keys must be strings enclosed in double quotes. JSON uses commas between members and values, but it does not allow a trailing comma after the final item. Whitespace outside strings is generally used for readability and does not change the data.
Checklist by scenario
When a parser reports a syntax error
- Read the location as a clue, not an absolute diagnosis. A parser may point at the character where it can no longer continue. The actual mistake may be immediately before it.
- Format the smallest section that fails. If the full document is large, isolate the suspected object or array and validate that fragment.
- Inspect punctuation around the location. Check the preceding comma, colon, quote, bracket, and brace.
- Look for smart punctuation. Curly quotes copied from a document editor are not the same as JSON double quotes.
- Check for comments and trailing commas. Some programming-language parsers accept extensions that strict JSON parsers reject.
When the JSON is valid but the API rejects it
- Compare the top-level type. Confirm whether the endpoint expects an object such as
{...}or an array such as[...]. - Compare property names exactly. Case, underscores, hyphens, and singular-versus-plural names can all matter.
- Check nesting. An API may expect
{"user": {"name": "Sam"}}while your client sends{"name": "Sam"}. - Check types. The string
"42", number42, booleantrue, andnullare different values. - Check required and optional fields. An omitted field may have different meaning from a field explicitly set to
null. - Inspect the request headers and body together. A correctly formatted body can still be sent with an unsuitable content type or to the wrong endpoint.
When comparing two JSON documents
First decide what kind of difference matters. A text comparison treats these as different:
{"name":"Ada","active":true}{"active":true,"name":"Ada"}A structure-aware comparison may treat them as equivalent because object member order is not normally the point of an API comparison. Use a JSON-aware diff when you need to identify changed paths, added or removed fields, and type changes. Then check:
- Top-level object versus array
- Added, removed, or renamed keys
- Values that changed type
- Arrays with changed order or length
- Nested objects that moved to a different path
- Empty strings, empty arrays, missing fields, and
nullvalues
For arrays, clarify whether order is meaningful. An ordered list of steps should usually be compared by position. A set of labels may be better compared as members, depending on the application’s rules.
When strings contain code, paths, or Unicode
JSON strings use escaping for characters that would otherwise change the document. A quote inside a string is written as ', a backslash as \\, and a line break may be represented with \n. Remember that escaping can occur at more than one layer. A JSON string embedded inside JavaScript, a shell command, or another serialized format may need escaping for both the outer language and JSON.
Keep Unicode text intact when possible, but inspect the source and destination encodings if characters appear corrupted. A validator can confirm JSON grammar; it cannot confirm that every downstream system displays or stores text as intended.
What to double-check
Use the exact payload
Do not diagnose a prettified example if the application sends a transformed version. Capture the request body or response as close as possible to the network boundary. Logging should be careful around credentials, personal data, and tokens. If you need to inspect a token format, use the safety guidance in the JWT debugging guide and avoid pasting sensitive production values into an untrusted tool.
Separate syntax from semantics
Validation answers “Can a JSON parser read this?” It does not answer “Is this acceptable to the API?” For semantic checks, use the endpoint documentation, an agreed schema, request examples, or automated contract tests. Record the expected path and type for fields that repeatedly cause failures.
Check numbers and dates deliberately
JSON has a number value, but applications may impose limits or convert numbers differently. Large identifiers are especially worth checking across languages and storage layers. Dates are represented as strings unless an application defines another convention, so verify the expected format, timezone, and precision rather than assuming that every ISO-looking value is accepted.
Inspect generated JSON
Prefer a language’s JSON serializer over manually joining strings. Serialization handles quoting and escaping more reliably. If a generated payload fails, log the serialized output—not only the source object—and validate that exact output.
Common mistakes
| Error message or symptom | Likely area to inspect |
|---|---|
| Unexpected token or character | Previous comma, quote, colon, comment, or unsupported extension |
| Unexpected end of input | Missing closing quote, bracket, or brace; truncated response |
| Expected property name | Unquoted key, extra comma, or malformed object member |
| Valid JSON, rejected request | Wrong endpoint, header, field name, nesting, or value type |
| Works in one tool but not another | Parser extensions, coercion, or different schema checks |
- Using single quotes: JSON requires double quotes for strings and object keys.
- Adding comments: Comments may be supported by a configuration format derived from JSON, but they are not part of standard JSON syntax.
- Confusing JavaScript with JSON: Variables, functions,
undefined, and unquoted object keys belong to JavaScript, not plain JSON. - Changing too much at once: Fix one error, validate, and retest so the next failure remains visible.
- Comparing formatted text instead of data: Indentation and key order can create noise in a text diff.
- Assuming null means missing: Many APIs distinguish among an omitted property, a null property, and an empty value.
A free online JSON beautifier can be convenient for non-sensitive samples, but do not paste secrets, access tokens, private customer data, or proprietary payloads into a third-party service unless your organization permits it. For sensitive data, use a local formatter, editor extension, or command-line validator.
When to revisit
Keep this checklist near your API testing and fixture workflow, and revisit it whenever the underlying inputs change. Review payload examples before a release, after an API version change, when a backend model is renamed, or when a frontend starts receiving a new response shape. It is also useful before seasonal planning cycles when integrations, imports, or scheduled jobs may be refreshed.
When a tool, runtime, serializer, or validation library changes, rerun representative fixtures rather than assuming identical behavior. Include cases with nested objects, arrays, Unicode, nulls, empty values, and deliberately invalid syntax. If a recurring job produces the payload, review its schedule and failure handling alongside the data; the cron expression guide covers a separate but related part of that workflow.
Action checklist:
- Save a minimal valid example and a minimal failing example.
- Record the expected top-level type and important field types.
- Validate the exact serialized request or response.
- Compare documents by structure, not only by formatted text.
- Remove secrets before sharing examples or using online developer tools.
- Turn the discovered failure into a regression test or fixture.
That final step turns a one-time JSON syntax error into a durable improvement to your API payload debugging process.