A JSON formatter can make a difficult API response readable, but formatting alone does not prove that the data is valid or safe to use. This guide explains how to format, validate, repair, and review JSON with an online developer tool or local command-line workflow, including practical checks for commas, quotes, nesting, duplicate keys, null values, and sensitive data.
Overview
JSON is a compact text format for structured data. It is common in API request and response bodies, frontend fixtures, configuration files, environment-driven settings, and test data. Its rules are deliberately small: objects use quoted property names, arrays use square brackets, strings use double quotes, and values must be valid JSON types. A single missing comma or unescaped quotation mark can prevent an entire response from parsing.
A JSON formatter, sometimes called a JSON beautifier, adds indentation and line breaks so that nested data is easier to inspect. A JSON validator online checks whether the text follows JSON syntax and usually reports an approximate location for a problem. These tools solve different parts of the same task:
- Format: Make valid JSON easier to read.
- Validate: Confirm that a document can be parsed as JSON.
- Repair: Correct syntax without changing the intended data.
- Inspect: Review types, nesting, missing fields, and unexpected values.
Formatting does not convert JavaScript into JSON. For example, this JavaScript-style object is not valid JSON because its property name is unquoted and it uses a single-quoted string:
{ userId: 'u-104', active: true }
The JSON equivalent is:
{
"userId": "u-104",
"active": true
}
For occasional debugging, an online formatter is convenient. For credentials, customer records, internal URLs, or production payloads, prefer a local tool or redact the data first. A formatter should never be treated as a secure storage location merely because it runs in a browser.
Checklist by scenario
When an API response is hard to read
- Copy the response from the Network panel or application log.
- Remove access tokens, cookies, authorization headers, personal data, and internal identifiers before using an online tool.
- Run the redacted text through a JSON validator.
- Apply two- or four-space indentation according to your team convention.
- Inspect the root value. Confirm whether it should be an object or an array.
- Check representative records for expected fields and data types.
For browser debugging, the Network panel can provide useful context about the request method, status, headers, and response body. If the payload appears truncated or differs from what the UI receives, use the request details rather than relying only on a copied console value. See the Chrome DevTools Network Panel guide for a broader request-debugging workflow.
When a request body fails validation
- Confirm the request uses the intended
Content-Type, commonlyapplication/json. - Validate the exact body sent over the network, not only the object before serialization.
- Check for a missing comma between properties or array items.
- Check that every property name uses double quotes.
- Confirm that strings, booleans, numbers, arrays, objects, and
nullare represented with the intended types. - Compare the payload with the API contract or JSON Schema, if one exists.
Syntax validation answers “Can this text be parsed?” It does not answer “Does this request satisfy the API?” A payload can be valid JSON and still fail because a required property is absent, an identifier has the wrong type, or a value falls outside the accepted range.
When a configuration file will not load
First determine whether the file is actually JSON. JSON does not support comments, trailing commas, unquoted keys, or expressions. Tools that accept JSON-like formats may add their own rules, but a file accepted by one parser may fail in another. Validate against the parser used by the application, then review environment-specific values separately.
A local command-line check keeps the workflow repeatable. If Node.js is available, a compact validation command is:
node -e "JSON.parse(require('fs').readFileSync('payload.json', 'utf8')); console.log('Valid JSON')"
For formatted output, write the parsed value back with indentation:
node -e "const fs=require('fs'); const value=JSON.parse(fs.readFileSync('payload.json','utf8')); console.log(JSON.stringify(value, null, 2))"
Use a temporary file or standard output when experimenting. Avoid overwriting the original payload until the result has been reviewed.
When a nested array is difficult to inspect
Format the document, then follow one path at a time. For a response such as data.orders[0].items[0], verify each level: is data an object, is orders an array, and does each order contain an items array? This simple path-based review often exposes a mismatch between the assumed response shape and the actual one.
What to double-check
| Problem | What to inspect | Typical correction |
|---|---|---|
| Missing comma | Adjacent properties or array items | Add a comma between values, but not after the final item when strict JSON is required. |
| Wrong quotation marks | Property names and string values | Use straight double quotes, such as "name". |
| Unescaped text | Quotes, backslashes, and control characters inside strings | Escape embedded quotes as ' and backslashes as \\. |
| Incorrect nesting | Opening and closing braces or brackets | Match every { with } and every [ with ]. |
| Unexpected type | Values such as IDs, flags, and counts | Distinguish "42" from 42, and "false" from false. |
| Null value | Whether absence is allowed by the consumer | Do not silently replace null with an empty string, zero, or empty array. |
| Duplicate key | Repeated property names in one object | Remove ambiguity and confirm which value the API contract expects. |
Duplicate keys deserve special attention. A document may parse even when the same property appears more than once, but parsers and tools can handle the repeated value differently. Treat duplicates as a data-quality problem and fix the producer rather than relying on whichever value happens to win.
In code reviews, compare formatted payloads with a stable indentation style and a meaningful diff. Check the root shape, changed fields, added or removed array items, type changes, nullability, and whether a new field contains sensitive information. For repeatable checks, combine a formatter with the project’s linting, tests, and schema validation workflow. The JavaScript linting and formatting workflow provides related guidance for keeping automated checks consistent.
Common mistakes
- Confusing JSON with JavaScript: JSON has no comments, functions, variables,
undefined, or single-quoted strings. - Editing only the visible error: A parser often reports where it noticed a problem, not where the mistake began. Inspect the preceding property, comma, or quote.
- Assuming valid means correct: Syntax checks do not enforce required fields, business rules, or authentication requirements.
- Changing values while repairing syntax: Keep a copy of the original and make the smallest possible edit.
- Sharing unredacted payloads: Remove secrets and personal data before pasting into an online JSON formatter.
- Using visual formatting as a data comparison: A reordered object or changed number type can be easy to miss without a structured diff.
- Ignoring the producer: If malformed JSON is generated repeatedly, fix serialization at the source instead of repairing each response manually.
When to revisit
Return to this checklist whenever an API response fails to parse, a fixture changes, a configuration file is edited, or a payload is added to a code review. Revisit the workflow before a release or environment change when request schemas, authentication flows, or response shapes may differ.
Update your team’s formatter and validation instructions when tools, parsers, JSON Schema conventions, or command-line workflows change. Keep one small redacted example in the repository or documentation so contributors can test the expected process without handling production data.
Before closing a JSON-related task, confirm:
- The text is valid JSON according to the parser that will consume it.
- The root type and nested shape match the contract.
- Strings, numbers, booleans, arrays, objects, and null values have intentional types.
- Duplicate keys, trailing commas, and accidental comments are removed.
- Secrets and sensitive values were not exposed during debugging.
- The final change is covered by an appropriate test, fixture, schema check, or review note.
