JSON formatting, validation and debugging
Formatting makes JSON readable; validation determines whether it is valid JSON. Neither operation changes what the data means.
What a formatter actually changes
JSON represents objects, arrays, strings, numbers, booleans and null. An API can transmit all of that
on one line because whitespace outside strings is insignificant. A formatter parses the input and
writes the same structure with line breaks and indentation. For example,
{"user":{"id":42,"active":true},"roles":["reader","editor"]} becomes a hierarchy in
which the user object and each role are easy to scan. Keys, values and array order remain unchanged.
This distinction matters during debugging. Sorting properties, converting numeric-looking strings to numbers or removing duplicate keys would alter or reinterpret the input; those are not formatting. The GenericTools.dev formatter preserves parsed values and lets you choose indentation or a minified output.
Formatting, validation and minification
- Formatting adds whitespace for humans.
- Validation checks grammar, such as matching braces and correctly quoted strings.
- Minification removes unnecessary whitespace for a smaller transfer or stored value.
- Schema validation is a separate step that checks expected fields and data types.
Valid JSON can still be wrong for an application. {"port":"443"} is syntactically valid,
but a schema may require the port to be a number. Conversely, a server response can contain useful
data but fail JSON parsing because an error page or proxy returned HTML instead.
Common syntax errors and how to find them
Trailing commas
{"name":"Ada",} resembles JavaScript object syntax but is invalid JSON. Remove the comma before the closing brace or bracket.
Single quotes and unquoted keys
JSON requires double quotes around property names and string values. Write {"status":"ok"},
not {status:'ok'}. A double quote inside a string must be escaped as \".
Missing delimiters
A reported error position may be after the real mistake. If parsing fails near the next property, inspect the preceding value for a missing comma, quote, brace or bracket. Format smaller sections when a large payload is difficult to isolate.
Invisible or unexpected input
Copying a log line may include a timestamp before the opening brace. A UTF-8 byte-order mark, smart quotes from a document editor or literal control characters inside a string can also cause failure. Confirm that the input begins with an object or array and came from the response body rather than a log wrapper.
A reliable API debugging workflow
- Record the HTTP status and content type before inspecting the body.
- Validate and format the exact response without manually correcting it first.
- Locate the smallest object or array containing the unexpected value.
- Compare field names and types with the API contract or JSON Schema.
- Redact secrets before sharing a formatted example in a ticket or chat.
- Minify only when a compact copy is actually required.
Privacy and security
API payloads frequently contain bearer tokens, session identifiers, email addresses and internal IDs. The JSON Formatter performs its transformation in your browser, but browser-side processing does not make a secret suitable for screenshots, clipboard managers or shared devices. Replace sensitive values with realistic placeholders while preserving their data types.
Frequently asked questions
Does formatting change an API request?
No. A conforming JSON parser ignores insignificant whitespace. Characters inside quoted strings are still significant.
Why did a duplicate key disappear?
JSON interoperability guidance expects object names to be unique, but parsers handle duplicates differently. Many retain only the last value. Treat duplicate keys as a producer defect rather than relying on their order.
Can a formatter prove the data is safe?
No. It can confirm syntax, not authorization, business rules, schema compliance or whether a string contains malicious content.