JSON Formatter for API Debugging, Nine Common Errors and Their Fixes
A JSON parse error always reports a position, and the real mistake is almost always one token before it. Learning to read that pointer, plus the nine failure patterns below, turns a mysterious 400 response into a two-second fix.
Paste your payload into the JSON validator to get the exact line and character, and the formatter to expose structural problems that parse correctly but read badly.
How to read a JSON error message
Parsers say things like "Unexpected token } in JSON at position 214" or "Expected a property name, got ',' at line 7 column 3". Position is a character offset from the start of the document, and it points at the token where the grammar broke, not at the token that caused it.
So look one line up and one token back. In the overwhelming majority of cases, the true error is a missing comma after the previous value, or a comma that should not be there at the end of an object.
Convert the offset to a line instantly with the validator's line or column display instead of counting by hand, off-by-one counting is how people stare at valid JSON for ten minutes.
The nine errors that account for most broken payloads
1. Trailing comma. {"a":1,"b":2,} is invalid, JavaScript object literals tolerate it, JSON does not. Remove the final comma.
2. Single quotes. {'a':1} is invalid. JSON requires double quotes on both keys and string values. The most common cause is hand-writing JSON or pasting a JavaScript object.
3. Unquoted keys. {a:1} is a JavaScript literal, not JSON. Every key must be quoted.
4. Comments. // note and /* block */ are not legal JSON, even though many config files pretend otherwise. Strip them before sending the body, JSONC must be converted.
5. Unescaped quote inside a string. {"say":"he said "hi""} breaks at the inner quote. Escape it: "he said \"hi\"".
6. Backslashes. Windows paths like "C:\new\test" are dangerous: \n and \t are real escape sequences. Write each separator as a doubled backslash, or use forward slashes.
7. Literal control characters. A raw newline or tab inside a string is invalid, it must be \n or \t. Copying JSON out of a chat message is the usual origin.
8. Numbers with units or separators. "price": "1,200" parses as a string, while 1.200 is invalid if you meant a thousands separator. Send real numbers without grouping, or accept that the consumer must parse a string.
9. NaN, undefined, Infinity. These are not JSON values. undefined silently disappears when serialized in JavaScript, and NaN produces invalid output, validate before sending.
Structural mistakes that parse fine but still break the integration
These produce no error message, which is exactly why they cost more time than syntax failures.
Array versus object confusion. A parser expecting [{"id":1}] receiving {"id":1} is a contract mismatch, not a syntax error. Single-element responses are the classic case: XML-to-JSON converters turn one node into an object and many nodes into an array, so your code must handle both. The XML to JSON converter shows this immediately.
Nested stringified JSON. Some APIs return "data": "{\"status\":\"ok\"}", a JSON document escaped inside a string. Double-parse deliberately. Never guess which fields are wrapped.
Unicode escapes. \é and a literal é are equivalent, but they are not equivalent in logs. If your output looks wrong in one place and right in another, check the display layer, not the payload.
Key case. JSON keys are case-sensitive: userId and userid are two different fields, and mixed conventions inside one API are a frequent deserialization bug source.
Formatting for debugging, not for filing
Two-space indentation makes nesting obvious at a glance, and it is the reason formatters exist. Beyond aesthetics, use the formatter to reveal three things. How deep a value actually sits, whether an array contains homogeneous objects, and where a duplicated key appears, the last occurrence silently wins in most parsers.
For comparing two payloads, format both with identical settings and diff them, a one-property difference in an otherwise identical response usually identifies the failing record.
Large payloads deserve a different treatment. Format a truncated slice or convert to another structure to inspect, because a 40 MB response formatted in one block is unusable and slow. The JSON to XML converter is handy when you want tag-based navigation of a deep hierarchy.
Debugging the response versus debugging your request
When a 400 arrives, first validate the body you sent. Serialize it, paste into the validator, and read the pointer. When a 200 arrives but your app still fails, the response is valid JSON and your parser is mis-reading the shape, log the type of the problem field, array, object, string, null, rather than its value.
One habit removes most pain. Never hand-edit JSON that came from a serializer. Round-trip it through a validator after any manual change, because human eyes are excellent at missing a missing comma.
Conversions, JSON, XML, CSV and back
Integrations rarely stay in one format. Use CSV to JSON when a spreadsheet becomes an API payload, and JSON to XML for legacy SOAP services.
Two rules to keep conversions honest. First, CSV has no types, every field arrives as a string, so numbers, booleans and nulls must be coerced explicitly. Second, XML has no arrays. Repeating elements become arrays only by convention, and a lone element stays an object, which is the source of the classic bug where code works with one record but breaks with two.
Frequently Asked Questions
Why is my JSON invalid when it works in JavaScript?
Because JavaScript object literals are a superset of JSON: unquoted keys, single quotes, trailing commas, comments and undefined values are all legal in JS and illegal in JSON. Serialize the object with JSON.stringify to get valid JSON, or run the literal through the validator to see exactly which token breaks the grammar.
What does "Unexpected token in JSON at position 0" mean?
The document does not even start with a value. The usual causes are an empty response body, a UTF-8 BOM before the opening brace, HTML error page text instead of JSON, or a stray character copied from a log line. Inspect the first bytes rather than the structure.
Does formatting JSON change the data?
A correct formatter changes whitespace only, leaving numbers, strings and key order intact. Values can change if the tool re-serializes floats through a lossy path or converts big integers to floating point, so check large numbers and precision-sensitive figures after any format round trip.
Is it safe to paste API responses with secrets into an online tool?
Only when processing happens in your browser. Our formatter and validator run locally against the text you paste, with no submission to any server. Anything that uploads payloads is unsuitable for production tokens, API keys or customer records.
How do I find duplicate keys in a JSON object?
Format the document and compare the line count against the number of expected properties, a duplicate is parsed and then overwritten silently by most libraries. Search the formatted output for repeated property names at the same indentation level to confirm.
Why does my one-record response parse differently from a two-record response?
Because XML and CSV sources have no native array type. Converters wrap multiple repeated elements in an array but leave a single element as an object, so code that assumes an array fails on the first record. Normalize explicitly, or request JSON endpoints where the contract is fixed.