A JSON formatter makes structured data easier to read, while a JSON validator confirms whether a parser can accept it. This guide explains JSON syntax, shows before-and-after examples, and provides a reusable checklist for diagnosing malformed payloads, configuration files, and API responses without exposing sensitive data unnecessarily.
Overview
JSON is a text format built from objects, arrays, strings, numbers, booleans, and the null value. It is common in API requests and responses, application configuration, browser storage, and data-transfer workflows. Because JSON is strict, a single missing comma, extra character, or incorrectly escaped quote can prevent an entire document from being parsed.
A JSON formatter changes indentation and line breaks so the structure is easier to inspect. A JSON validator checks syntax and usually reports the approximate location of a parsing failure. These tools answer different but related questions: formatting helps you see the data, while validation helps confirm that the data is valid JSON.
When using a browser-based JSON formatter online, treat the input as potentially sensitive. Remove access tokens, passwords, personal information, production credentials, and private customer data before pasting. For confidential payloads, use a local editor, a command-line parser, or an approved internal tool instead.
JSON syntax reference
| Value | Valid form | Common issue |
|---|---|---|
| Object | {"name": "Ava"} | Keys must use double quotes and each key needs a colon. |
| Array | ["red", "green"] | Items are separated by commas; trailing commas are not valid standard JSON. |
| String | "hello" | Strings require double quotes, not single quotes. |
| Number | 42 or 3.14 | Do not add comments, currency symbols, or other text to a number. |
| Boolean | true or false | Boolean values are lowercase and are not quoted. |
| Empty value | null | null is unquoted and is different from an empty string. |
A JSON document normally has one top-level value. In API work, that value is often an object or an array. JSON also does not include native comments, dates, or undefined values. Applications may agree on conventions for representing those concepts, but the representation still needs to be valid JSON before a standard parser can read it.
Checklist by scenario
Formatting and validating a small JSON snippet
- Copy the complete snippet, including its first opening character and final closing character.
- Run it through a JSON formatter or validator.
- Read the reported line and column, then inspect a few characters before the indicated position. Parsers often detect a problem at the point where the structure becomes impossible, not where the mistake began.
- Confirm that every object key has a colon and that neighboring properties are separated by commas.
- Format the corrected document again and scan the resulting indentation for misplaced braces or brackets.
Checking nested objects and arrays
Work from the outside inward. First identify the top-level object or array. Then match each opening brace { with a closing brace }, and each opening bracket [ with a closing bracket ]. Check that arrays contain comma-separated values and that objects contain comma-separated key-value pairs.
For example, this compact input is valid but difficult to review:
{"user":{"id":27,"roles":["editor","reviewer"],"active":true}}
After formatting, the relationships are easier to verify:
{
"user": {
"id": 27,
"roles": [
"editor",
"reviewer"
],
"active": true
}
}
If a nested structure is large, validate smaller sections temporarily. Extract one object or array, check it independently, and then restore it to the parent document. This isolates whether the issue is in the nested value or in the surrounding commas and delimiters.
Inspecting escaped characters
JSON strings use double quotes. A double quote that belongs inside a string must be escaped with a backslash. Common escapes include ' for a quote, \\ for a backslash, \n for a line feed, and \t for a tab.
Invalid:
{"message": "The server said "ready""}
Valid:
{"message": "The server said 'ready'"}
Be careful when JSON is embedded inside another format, such as a JavaScript string, a shell command, or an HTML attribute. The outer format may require a second layer of escaping. Validate the actual string received by the parser rather than only the source code that constructs it.
Checking an API response or request body
- Capture the raw response body or request body before a client transforms it.
- Check the HTTP status, content type, and response body separately. A successful transport does not guarantee that the body matches the expected schema.
- Confirm that the body is actually JSON. An HTML error page, plain-text message, or empty response can cause a JSON parsing error even when the client expected JSON.
- Format and validate the body.
- Compare property names, data types, required fields, and nesting against the API contract.
- Remove tokens and personal data before saving a debugging example or sharing it with a colleague.
Syntax validation is not schema validation. A document can be valid JSON while still being unusable for an API because a required field is missing, a number is supplied as a string, or an enum value is unsupported. For contract-related troubleshooting, also review the API compatibility guide.
What to double-check
Before declaring the JSON valid
- Quotes: Use straight double quotes. Smart or typographic quotes copied from a document are different characters.
- Commas: Place commas between properties or array items, but not after the final item.
- Colons: Every object key must be followed by one colon and a value.
- Delimiters: Match braces and brackets in the correct nesting order.
- Value types: Keep strings, numbers, booleans, and
nulldistinct. Quote a value only when the receiving application expects a string. - Encoding: Check for invisible control characters, unexpected line breaks, or a byte-order mark when data comes from a file or external system.
- Duplicate keys: Avoid them. Parsers and platforms may handle repeated object keys differently, so the result can be ambiguous even if a particular tool accepts the document.
- Payload boundaries: Make sure the copied content does not include a log prefix, code-fence marker, HTTP header, or explanatory text around the JSON.
How to interpret common parser errors
Unexpected token: The parser found a character that cannot appear at that position. Look for single quotes, comments, an extra comma, or an unescaped quote nearby.
Unexpected end of input: The document ended before a string, object, or array was closed. Check the final section and count opening and closing delimiters.
Expected property name: The parser is inside an object and expects a quoted key. A trailing comma or an unquoted key is a common cause.
Unexpected character after JSON: A valid value may be followed by another value, a log message, or other non-JSON content. Confirm that the parser receives one complete document rather than concatenated responses.
Error locations are useful clues, not always exact answers. Start at the reported location, then inspect the previous property, string, or delimiter where the structure last looked correct.
Common mistakes
One frequent mistake is treating JavaScript object notation as JSON. JavaScript permits features such as unquoted property names, single-quoted strings, comments, and trailing commas in some contexts. Standard JSON does not. Convert the object deliberately instead of assuming code that looks similar will parse as JSON.
Another mistake is formatting without validating. Indentation can make malformed text look organized, but a formatter may stop at the first error or display only a partial result. Always confirm that the validator reports success and, for API work, separately check the expected schema.
Do not use a formatter to conceal sensitive data. A readable payload is still sensitive if it contains authorization headers, session identifiers, email addresses, internal URLs, or customer records. Redact values while preserving the data types and overall shape needed for debugging.
Finally, avoid fixing only the displayed example when the application generates the payload incorrectly. Trace the value back to its source and inspect serialization, character encoding, request construction, and any middleware that modifies the body. For a broader request-debugging process, see this API testing workflow.
When to revisit
Return to this checklist whenever an API contract changes, a configuration file is migrated, a new client or backend language is introduced, or a previously valid payload begins failing. It is also useful before deployment, after changing serialization code, and when a service starts returning a different content type or error format.
Tool behavior can vary by parser, language, and platform. If a formatter accepts input that another application rejects, treat the target application as the final authority and test with the same parser or runtime used in production. Recheck examples when your team changes validation rules, schema requirements, or the workflow used to capture API responses.
For a practical final pass, use this sequence:
- Redact secrets and personal data.
- Validate the complete raw document.
- Read the error location and inspect the preceding delimiter or string.
- Format the corrected JSON and review its nesting.
- Compare the structure and data types with the API or configuration contract.
- Test the exact request or application path that previously failed.
- Save a minimal, sanitized regression example if the issue could recur.
Formatting makes JSON readable; validation makes its syntax testable; contract checks make it useful to the receiving system. Keeping those steps separate gives you a reliable workflow for troubleshooting JSON as inputs, tools, and APIs change.