Skip to content

FIELD NOTES / A DECISION GUIDE

Format first. Validate the shape next.

A response arrives as one long line. Before tracing a missing field, give the data some space. Formatting exposes the structure without asking you to understand every value at once.

First decision: readability or a smaller payload?

Choose Format when you want to inspect an object, compare nested fields, or share a readable example. Two spaces are a useful default. Choose Compact when you need the same JSON with insignificant whitespace removed. Whitespace inside a string remains part of the value.

{"service":"relay-worker","checks":{"schema":true,"latency_ms":36}}

With two-space indentation, the formatter produces:

{
  "service": "relay-worker",
  "checks": {
    "schema": true,
    "latency_ms": 36
  }
}

Second decision: syntax or contract?

A syntax check asks whether the text follows JSON grammar. A contract check asks whether that JSON has the fields and types your application expects. The formatter handles syntax. A result can be valid JSON and still be the wrong response for your code: {"latency_ms":"slow"} is valid JSON, even if your application expects a number.

  • If the syntax fails, check the reported line and column. Look for a missing quote, comma, colon, or closing bracket.
  • If syntax passes but your code fails, compare the structure with your API contract or schema.
  • If a duplicate-key warning appears, inspect it before copying the result into another parser.

What this bench preserves

Some formatters convert all numbers into JavaScript numbers. That can change a large identifier. FormatBits formats the original tokens, so 9007199254740993 keeps every digit. It also keeps key order and string escapes. Unicode text such as δΈ–η•Œ πŸ‘‹ stays intact.

Duplicate object keys are accepted by JSON grammar, but consumers can disagree about which value to keep. The bench preserves both entries and adds a warning. For example, {"stage":"review","stage":"ready"} keeps both keys in the result. Resolve the ambiguity in your source rather than relying on a parser’s preference.

If the check fails

Start at the reported position, then inspect the preceding token. A trailing comma such as {"ready":true,} is invalid JSON. JavaScript object syntax with unquoted keys is also invalid. Your input remains editable when a check fails; the result clears so an older successful check cannot be mistaken for the current input.

The bench accepts at most 256 KiB of UTF-8 input, 50,000 tokens, and 128 levels of nesting. For a larger response, isolate the relevant object. A successful formatting check is a useful first step, followed by checking the application’s expectations.