Invalid JSON: how to spot errors fast (without wasting time)
Practical guide: why JSON breaks, real examples, common mistakes, debugging tips, and FAQ.
How to use this guide well
These guides are more useful when you read them as operational help, not as filler documentation.
Do not read linearly if you do not need to. Jump to the section that looks closest to the incident, payload, or config you are debugging.
The useful part is usually in the caveat, not in the snippet itself: timezone, dialect, schema, audience, type inference, or portability.
Once the reasoning is clear, use the related tool to inspect the real value, payload, or expression instead of working from memory.
What you will find in this guide
A quick scan before you dive in.
7
2
json, debugging, api
Apply this guide in 3 steps
A short workflow tuned to the type of issue this guide covers.
Work with the exact payload, config, or identifier that is failing instead of rebuilding it from memory.
Use the examples to understand the failure mode first, then adapt them to your own environment and stack.
Once the reasoning is clear, inspect the live value with the matching tool and share a sanitized example if you need help.
What this guide solves
JSON is strict. “Invalid JSON” is usually caused by copy/paste, huge payloads, or mixing JSON with JS object syntax.
The goal is a short routine: isolate the error, fix it, and produce readable output for bug reports.
30-second checklist
• Trailing commas at the end of objects/arrays?
• Single quotes used for keys/strings?
• Non-JSON values (NaN, Infinity, undefined)?
• Literal newlines inside a string (instead of \n)?
• Is it JSON5 (comments, trailing commas, unquoted keys)?
Real example 1: trailing comma
JSON does not allow trailing commas. Fix: remove the last comma.
{
"a": 1,
"b": true,
}
Real example 2: newline inside a string
Inside strings, newlines must be escaped as \n.
{
"message": "Line 1\nLine 2"
}
Common mistakes (and typical fixes)
• Single quotes: switch to double quotes.
• Unquoted keys: add double quotes.
• NaN/Infinity/undefined: replace with null or valid values.
• Comments: remove them (standard JSON does not support comments).
• Dates: use ISO strings.
Debugging tips
• Save real request/response bodies when debugging APIs.
• Avoid string concatenation; prefer JSON.stringify for correct escaping.
• Format and redact sensitive fields before sharing.
FAQ
• Does the tool auto-fix invalid JSON? No: it formats valid JSON and shows clear errors otherwise.
• Is my input sent to a server? No: local processing.
• JSON5 support? No.
Related tools
Use the matching tool when you want to validate or reproduce the issue described in this guide.
Keep exploring this topic
Move between deep guides and shorter task-focused articles so the site works like a connected knowledge base, not a dead end.
Real-world comparison: when to choose YAML or JSON, examples, pitfalls (indentation/types), and a production checklist.
Practical checklist: tokens, headers, logs, screen sharing, extensions, and how to redact data in tickets.
A repeatable workflow to debug login/401 issues: clean token, inspect claims, convert exp, format errors, isolate root causes.
Real snippets to validate JSON and produce readable output (pretty print). Includes dependencies when the language has no built-in JSON.
Real snippets to convert header-based CSV into JSON across languages. Includes dependencies when CSV parsing is not available in the standard library.
Real snippets to export JSON to CSV across languages. Useful for reporting, handoff, and pipelines where rows and columns are still the expected format.