Skip to main content

Command Palette

Search for a command to run...

JSON Formatting Is Not Validation: A Practical Debugging Checklist

Updated
•2 min read•View as Markdown
U
Software Engineer & Full-Stack Developer. Creator of DevOmniTools (free private in-browser developer utilities). Writing about web architecture, APIs, debugging, and production engineering.

A neatly indented API response can still contain the wrong data. Before treating JSON as trustworthy, separate three questions: does it parse, does it match the expected structure, and does it satisfy your application rules?

1. Check syntax first

This is valid JSON:

{"userId":"42","active":true,"roles":["reader"]}

Single-quoted keys, comments, and trailing commas are not part of standard JSON. If parsing fails, inspect the reported position and the surrounding characters before changing the whole document.

2. Formatting improves readability

Indentation helps you see nested objects and arrays. It does not prove that a field exists or has the right type. In the example above, userId is a string. An API expecting an integer may reject it even though the JSON parses perfectly.

A reproducible browser-console example:

const payload = JSON.parse(' {"userId":"42","active":true} ');
console.log(JSON.stringify(payload, null, 2));
console.log(typeof payload.userId); // "string"

Use synthetic data for this exercise. Do not paste production credentials into examples or shared consoles.

3. Check the contract separately

Compare the parsed document with the API contract or a JSON Schema. Check required fields, allowed values, nesting, and types. Then check business rules: an order can have valid numeric fields while still containing an impossible quantity. Keep error messages specific enough to identify the failing field.

4. Inspect the actual response

In browser developer tools, inspect the network response status, headers, and body. An endpoint may return an HTML error page where your client expects JSON. Also distinguish an absent property from a property whose value is null; those cases can carry different meanings in an API.

5. Keep debugging data small

Reduce the response to the smallest synthetic example that reproduces the failure. Preserve the relevant nesting and types while removing tokens, personal information, and confidential values. This makes a bug report easier to review and safer to share.

Where DevOmniTools fits

I build DevOmniTools, a collection of browser-based developer utilities. Its core transformations run locally in the browser; optional AI assistance requires separate consent. Use the utilities to inspect and format a synthetic sample, then validate it against your application contract. A readable output is one step in that workflow.

Checklist: parse → format → check the contract → check business rules → reproduce with synthetic data.

What JSON issue causes the most debugging time in your projects: syntax, unexpected types, or inconsistent API contracts?

3 views
A

For an order-message boundary, I would keep valid JSON with volume: 0 as a negative fixture beside a correctly typed, permitted quantity. Also keep a missing quantity separate from null: parser success and a successful HTTP response must not stand in for an accepted order state. Return the field-specific failure before any order submission, so a transport retry cannot hide a validation failure.