CalcoWorks
Back to Blog

Pretty-Printed JSON Saved Me From a 2 A.M. “Invalid Payload” Spiral

Published 6 min readAdmin

Last updated

jsonapiformatterdebuggingdeveloper tools

The error said invalid payload. The screenshot said the payload “looked fine.” At 2 a.m., looking fine is not a strategy.

I paste first, format second, validate third. Emotion drops when structure is visible.

What pretty-printing actually buys you

  • Mismatched braces become obvious
  • Duplicate keys stop hiding in a one-line blob
  • Nested arrays stop looking like alphabet soup

My three-tab ritual

  1. Paste the raw body into JSON Formatter.
  2. If it fails, run JSON Validator and read the position hint.
  3. Compare with a known-good sample from yesterday’s successful request—not from memory.

Quick tip: Disable “smart quotes” in docs editors before copying sample JSON from Notion or Word.

Frequent villains

  • Trailing commas (valid in JS, not in JSON)
  • Single quotes instead of double quotes
  • Comments left in from a JS object literal
  • Unescaped newlines inside strings

Try it free: Format the messy bit with JSON Formatter, then validate.

More utilities: Developer Tools.

Logs vs real bodies

Some gateways truncate logged bodies. If the formatter says the JSON is fine but the server disagrees, ask whether you’re debugging a truncated log line.

Binary-to-text accidents in logs insert replacement characters that invalidate strings. Copy from a raw capture when possible.

I keep a redacted sample of a good payload next to the failing one. Diffing keys is faster than rereading prose errors.

Schema assumptions

Valid JSON can still be the wrong shape. Formatter success ≠ API success. Check required fields after it parses.

Null vs missing keys behave differently across stacks. Decide which your API means and stick to it.

Numbers that should be strings (leading zeros, IDs) are a classic silent bug after a “helpful” transform.

Minify only when you mean it

Minified JSON is for transport. Humans deserve whitespace while investigating.

If a partner demands minified samples in tickets, minify as the last step after the content is correct.

Beautifiers don’t fix business logic—they just stop you lying to yourself about structure.

Team habits that prevent 2 a.m.

Store example requests next to the endpoint docs. Stale examples cause more outages than clever code.

When someone pastes JSON in chat, ask them to format first. Thread length drops.

Mock API fixtures should be validated in CI so fixtures don’t rot.

Related tools when JSON isn’t the only mess

Base64 wrappers around JSON need decoding before formatting. Don’t pretty-print the envelope by mistake.

JWT payloads are base64url JSON—decode, then format, then never paste production tokens into public tools carelessly.

If you’re building fixtures, a mock API generator helps you stop hand-writing brittle samples at midnight.

Logs vs real bodies (continued)

Some gateways truncate logged bodies. If the formatter says the JSON is fine but the server disagrees, ask whether you’re debugging a truncated log line.

Binary-to-text accidents in logs insert replacement characters that invalidate strings. Copy from a raw capture when possible.

I keep a redacted sample of a good payload next to the failing one. Diffing keys is faster than rereading prose errors.

Schema assumptions (continued)

Valid JSON can still be the wrong shape. Formatter success ≠ API success. Check required fields after it parses.

Null vs missing keys behave differently across stacks. Decide which your API means and stick to it.

Numbers that should be strings (leading zeros, IDs) are a classic silent bug after a “helpful” transform.

Minify only when you mean it (continued)

Minified JSON is for transport. Humans deserve whitespace while investigating.

If a partner demands minified samples in tickets, minify as the last step after the content is correct.

Beautifiers don’t fix business logic—they just stop you lying to yourself about structure.

Team habits that prevent 2 a.m. (continued)

Store example requests next to the endpoint docs. Stale examples cause more outages than clever code.

When someone pastes JSON in chat, ask them to format first. Thread length drops.

Mock API fixtures should be validated in CI so fixtures don’t rot.

Related tools when JSON isn’t the only mess (continued)

Base64 wrappers around JSON need decoding before formatting. Don’t pretty-print the envelope by mistake.

JWT payloads are base64url JSON—decode, then format, then never paste production tokens into public tools carelessly.

If you’re building fixtures, a mock API generator helps you stop hand-writing brittle samples at midnight.

Logs vs real bodies (continued)

Some gateways truncate logged bodies. If the formatter says the JSON is fine but the server disagrees, ask whether you’re debugging a truncated log line.

Binary-to-text accidents in logs insert replacement characters that invalidate strings. Copy from a raw capture when possible.

I keep a redacted sample of a good payload next to the failing one. Diffing keys is faster than rereading prose errors.

Schema assumptions (continued)

Valid JSON can still be the wrong shape. Formatter success ≠ API success. Check required fields after it parses.

Null vs missing keys behave differently across stacks. Decide which your API means and stick to it.

Numbers that should be strings (leading zeros, IDs) are a classic silent bug after a “helpful” transform.

Minify only when you mean it (continued)

Minified JSON is for transport. Humans deserve whitespace while investigating.

If a partner demands minified samples in tickets, minify as the last step after the content is correct.

Beautifiers don’t fix business logic—they just stop you lying to yourself about structure.

Team habits that prevent 2 a.m. (continued)

Store example requests next to the endpoint docs. Stale examples cause more outages than clever code.

When someone pastes JSON in chat, ask them to format first. Thread length drops.

Mock API fixtures should be validated in CI so fixtures don’t rot.

Related tools when JSON isn’t the only mess (continued)

Base64 wrappers around JSON need decoding before formatting. Don’t pretty-print the envelope by mistake.

JWT payloads are base64url JSON—decode, then format, then never paste production tokens into public tools carelessly.

If you’re building fixtures, a mock API generator helps you stop hand-writing brittle samples at midnight.

Logs vs real bodies (continued)

Some gateways truncate logged bodies. If the formatter says the JSON is fine but the server disagrees, ask whether you’re debugging a truncated log line.

Binary-to-text accidents in logs insert replacement characters that invalidate strings. Copy from a raw capture when possible.

I keep a redacted sample of a good payload next to the failing one. Diffing keys is faster than rereading prose errors.

Schema assumptions (continued)

Valid JSON can still be the wrong shape. Formatter success ≠ API success. Check required fields after it parses.

Null vs missing keys behave differently across stacks. Decide which your API means and stick to it.

Numbers that should be strings (leading zeros, IDs) are a classic silent bug after a “helpful” transform.

Minify only when you mean it (continued)

Minified JSON is for transport. Humans deserve whitespace while investigating.

If a partner demands minified samples in tickets, minify as the last step after the content is correct.

Beautifiers don’t fix business logic—they just stop you lying to yourself about structure.

Team habits that prevent 2 a.m. (continued)

Store example requests next to the endpoint docs. Stale examples cause more outages than clever code.

When someone pastes JSON in chat, ask them to format first. Thread length drops.

Mock API fixtures should be validated in CI so fixtures don’t rot.

Related tools when JSON isn’t the only mess (continued)

Base64 wrappers around JSON need decoding before formatting. Don’t pretty-print the envelope by mistake.

JWT payloads are base64url JSON—decode, then format, then never paste production tokens into public tools carelessly.

If you’re building fixtures, a mock API generator helps you stop hand-writing brittle samples at midnight.