When a JSON error appears deep inside an API client, the fastest fix is usually a consistent inspection routine rather than a larger parser.
First, save the raw response exactly as received. Then format it so nesting and delimiters are visible. Check the first character to confirm whether you received an object, an array, a string, or an HTML error page disguised as a 200 response.
Next, validate the contract: required keys, value types, and whether null is allowed. Search for duplicate keys and unexpected arrays, especially when the payload was assembled from several services. If the response can contain user text, remember that escaped quotes and newline characters are valid JSON even when they look unusual.
For debugging logs, keep a readable copy and redact tokens, cookies, and personal data before sharing. Minify only when sending a final payload where bandwidth matters. A short checklist like this turns most “unexpected token” messages into a precise location and an actionable fix.
A browser-based formatter can help inspect a sample quickly:
https://www.lizecheng.net/dev/json-formatter/?utm_source=dev.to&utm_medium=forum&utm_campaign=lizely_daily_20260907&utm_content=json-formatter
Top comments (0)