How to Fix Invalid JSON and Choose Between Formatting and Minifying
Find common JSON syntax errors, understand why valid JSON can still break an API, and learn when to use readable formatting or compact output.
Why does JSON that looks right still fail?
JSON has a stricter syntax than a JavaScript object literal. Object keys and strings need double quotes. A trailing comma or a comment can make a document invalid even when a developer recognizes the intended data. Fix the syntax before investigating an API's business rules.
For example, {"name":"Mira","active":true} is JSON, while {name:"Mira",active:true,} is not. Start with the earliest reported parser error. One missing quote can make several later lines look broken, so changing every highlighted line at once can create more confusion.
Use a formatter to locate the first problem
Paste a sanitized sample into StatFlare's JSON Formatter. If parsing fails, inspect the reported position and the characters immediately before it. Check matching brackets, commas between values, and quotes around strings. After each correction, validate again before making another change.
Once it parses, expand the tree and inspect the field you care about. A nested object may be valid but placed under the wrong parent. Searching for a key and copying its path is often easier than scanning a large response line by line.
Try it free: JSON Formatter
Validate, format, minify, and explore JSON in a browser-based tree viewer.
Five mistakes to check before rewriting the payload
Work through these syntax checks first. The JSON standard defines the permitted values and grammar; an API can impose additional requirements on top of that format.
- Use double quotes for keys and strings, not single quotes or typographic quotation marks.
- Remove the comma after the last member of an object or the last item in an array.
- Remove comments; ordinary JSON has no comment syntax.
- Use true, false, and null in lowercase. Values such as undefined and NaN are not JSON values.
- Escape a literal newline inside a string as \n, and a literal backslash as \\.
Formatting and minifying solve different problems
Formatting adds indentation and line breaks so a person can review structure. Minifying removes unnecessary whitespace to produce a compact representation. Neither operation supplies missing required fields or turns a string into the number your API expects.
Keep identifier-like values as strings when their exact digits matter. A browser-based formatter parses numbers using JavaScript's numeric representation, so very large numeric identifiers can lose precision during parsing and serialization. Formatting is also inappropriate for byte-for-byte signed content: even a harmless whitespace change changes its bytes.
Frequently asked questions
Does valid JSON guarantee a successful API request? No. The server may reject missing fields, wrong types, unauthorized requests, or values outside its accepted range.
Will minifying encrypt my data? No. Compact JSON remains readable data. Remove secrets from samples before sharing them.
Can formatting repair duplicate keys? Do not rely on it. Parsers may retain only one value; remove duplicates in the original source and decide which value is intended.
JSON Formatter
Validate, format, minify, and explore JSON in a browser-based tree viewer.
Written by
Jayesh Gavit
Founder, StatFlare
Jayesh Gavit is the founder of StatFlare, a free YouTube channel analytics platform used by thousands of creators and marketers. He has spent years studying the YouTube algorithm, audience behavior, and creator monetization patterns. Outside of building StatFlare, Jayesh creates videos at @jayeshverse covering software, indie product building, and the creator economy.
Free Tools