Document Workflow
Format JSON for API debugging
Isolate, redact, format, and validate an API JSON body without rewriting number text or hiding duplicate keys, then check its schema separately.
Written and tested by SimpleWebUtilsPublished: Reviewed:
How this workflow was checked
To check “API response with nested user data”, we used JSON Formatter with the guide's exact source data and applied “Format without reserializing values”. The output had to match the documented result; evidence for “Formatting logs that include non-JSON prefixes” and “Debugging escaped JSON without decoding it first” was reviewed before recording the check.
The minified response formatted into the documented user and meta hierarchy without changing IDs, role order, requestId, or numeric duration.
Problem
API clients, browser consoles, and logs often mix a compact JSON body with headers, timestamps, wrapper strings, or sensitive identifiers. A parse-and-reserialize shortcut can also hide duplicate keys or rewrite numeric text, making the debug sample differ from the failing payload.
Sources and standards
These authoritative references define the formats or security boundaries used in this workflow. Tool-specific verification is documented separately above.
When to use this
- A REST or GraphQL response is valid but too dense to inspect.
- A test fixture fails because the JSON payload is malformed.
- A webhook body needs to be checked before it is pasted into an issue or support ticket.
- A copied network response contains escaped JSON that must be separated from headers, logs, or wrapper fields.
- A payload parses successfully but still needs duplicate-key, schema, or numeric-precision review before use.
Steps
- Step 1
Isolate one complete JSON body
Copy only the body from the API client or browser network panel. Remove status lines, headers, timestamps, log prefixes, and text after the root value so the sample matches one complete JSON document.
- Step 2
Redact before processing or sharing
Replace tokens, cookies, emails, account IDs, request signatures, and customer fields with stable synthetic markers. Browser-local processing does not override your data-handling policy.
- Step 3
Format without reserializing values
Apply two- or four-space indentation and keep the exact source available. The formatter changes structural whitespace while preserving duplicate properties and number spellings such as 1e+3.
- Step 4
Resolve syntax and duplicate-key diagnostics
Use the one-based line and column to fix the comma, colon, quote, escape, number, closing delimiter, multiple root, or trailing content. Treat every duplicate path as a data-quality failure even when the syntax is parseable.
- Step 5
Check the API contract separately
Compare required names, types, nullability, value ranges, array cardinality, and identifier precision against JSON Schema or the application contract. Valid JSON syntax alone does not prove a valid API payload.
- Step 6
Minify or export only the reviewed result
After comparing the corrected document with the failing request, minify it only when a fixture, environment field, or command requires compact text. Copy and download the exact reviewed output.
Example
API response with nested user data
Input
{"user":{"id":42,"email":"dev@example.com","roles":["admin","billing"]},"meta":{"requestId":"req_9f21","durationMs":128}}Output
{
"user": {
"id": 42,
"email": "dev@example.com",
"roles": [
"admin",
"billing"
]
},
"meta": {
"requestId": "req_9f21",
"durationMs": 128
}
}Common mistakes
Formatting logs that include non-JSON prefixes
Remove timestamps, log levels, and labels before validating. JSON parsers expect the first character to be an object, array, string, number, boolean, or empty-value literal.
Debugging escaped JSON without decoding it first
If the payload is a JSON string inside another JSON object, decode or unescape that field before treating it as a standalone response.
Leaving comments or trailing commas in copied samples
JavaScript examples, API docs, and console snippets often include comments or trailing commas. Remove them before validation because strict JSON accepts neither.
Forgetting that escaped JSON is still a string
A value such as "{\"id\":42}" must be unescaped before it can be inspected as an object. Formatting the wrapper object alone will not reveal the nested structure.
Sharing formatted payloads with live identifiers
Pretty output makes account IDs, emails, tokens, and request IDs easier to spot. Redact those fields before pasting the formatted JSON into chat, tickets, or public examples.
Assuming valid syntax proves a valid API contract
A document can parse while missing required fields, using the wrong semantic type, exceeding a range, or containing a number that a downstream runtime cannot represent exactly. Run schema and application checks separately.
FAQ
Does formatting JSON change the data?
This formatter changes structural whitespace while preserving duplicate properties and source number spellings rather than rebuilding the document from JavaScript values. It removes one leading byte-order mark before producing output.
Why does valid JSON from an API still look unreadable?
Many APIs send minified JSON to reduce payload size. It is valid for machines but difficult for humans to inspect until it is formatted.
Should I paste production secrets into a JSON formatter?
Avoid pasting secrets into any tool unless you understand where processing happens. SimpleWebUtils tools are designed for browser-side workflows, but sensitive tokens should still be redacted before sharing or saving.
What should I check when formatted JSON still fails validation?
Check for log prefixes, smart quotes, trailing commas, comments, unescaped control characters, and partially copied responses. Then validate the smallest object or array that still reproduces the error.
How do I debug JSON that is inside another JSON string?
Format the outer object first, copy only the string field that contains escaped JSON, unescape it, and then format that inner value as its own object or array.
Should I keep numbers as strings after formatting?
Formatting does not decide data types. Keep IDs, postal codes, account numbers, and other leading-zero values as strings unless the API contract explicitly expects numbers.
What limits apply to this browser workflow?
The formatter and validator accept up to 10,000,000 UTF-8 bytes and 512 nesting levels. Manual mode reduces repeated work during editing but does not increase those limits; larger inputs need a streaming or command-line parser.