Skip to content
← cd ../posts
[Developer Tools]2 min read

Format First, Debug Faster: A JSON Troubleshooting Workflow

A practical JSON troubleshooting workflow for developers: format payloads, spot type mismatches, compare responses, and avoid debugging the wrong data.

Sagar Kumar Sethi
Abstract JSON payload expanding into structured cards with validation indicators

JSON bugs rarely announce themselves clearly. A payload fails validation, a field disappears, a boolean arrives as a string, or an API response looks correct until one nested object is missing.

The fastest way to debug JSON is not to stare harder at minified text. Format it first, reduce it to the smallest example, then compare what changed.

Why JSON Bugs Waste Time

JSON feels simple because the syntax is small. The mistakes are usually not syntax mistakes. They are shape mistakes: missing fields, wrong nesting, unexpected nulls, duplicated objects, and values that have the right spelling but the wrong type.

  • A number is sent as a string.
  • A boolean is sent as "true" or "false".
  • An array is empty when the UI expects at least one item.
  • A nested object is missing after serialization.
  • A field name changed from snake_case to camelCase.

The Workflow

1. Format Before You Read

Start by formatting the payload. This gives your eyes a real structure to scan and makes wrong nesting visible. Use the JSON Formatter at /tools/json-formatter/ for this step.

javascript
{
  "userId": "user_123",
  "limit": "25",
  "includeArchived": "false",
  "filters": {
    "status": [
      "open",
      "pending"
    ]
  }
}

That example looks reasonable, but limit and includeArchived are strings. If the API expects a number and a boolean, validation or filtering can break even though the payload "looks fine".

2. Check Types Explicitly

Do not only check whether a value exists. Check what type it is. Many production bugs come from values crossing boundaries between form fields, URLs, local storage, and APIs.

  • Numbers from form inputs often start as strings.
  • Query parameters are always strings until parsed.
  • Empty fields can become empty strings, null, or undefined.
  • Dates may be ISO strings, Unix seconds, or Unix milliseconds.

3. Compare Working and Broken Payloads

When you have one payload that works and one that fails, stop reading them separately. Compare them directly. Use the JSON Diff tool at /tools/json-diff/ and look for the smallest meaningful difference.

  • Which field exists only in the working request?
  • Which value changed type?
  • Which nested object moved?
  • Which array changed order or length?

4. Reduce to the Smallest Failing Example

Remove fields until the request still fails with the fewest possible keys. This helps separate real requirements from noise. A small failing payload is easier to reason about and easier to hand to another developer.

5. Validate the Response Shape

Do not assume the request is the problem. Format the response too. A backend can accept the payload correctly but return data in a shape the frontend no longer expects.

  • Check required fields.
  • Check null values.
  • Check pagination metadata.
  • Check arrays that might be empty.
  • Check whether errors are returned in a consistent format.

A Simple JSON Debugging Checklist

  • Format the request body.
  • Format the response body.
  • Check field names.
  • Check value types.
  • Compare working and failing examples.
  • Reduce to the smallest failing payload.
  • Capture the exact status code and error body.

JSON debugging gets much easier when you make the data visible. Format first, compare second, change code last.

Related Posts

Useful Tools For This Topic

explore_all →