Common mistakes people make with the JSON Formatter
Most poor results from the JSON Formatter are not faults in the tool. They are small slips in the pasted text, or in which output gets copied afterwards. The tool itself uses exact parsing, so when it reports “Invalid JSON”, the text really is invalid, and the error message names the exact spot. Each of the five mistakes below has a quick fix, and the check at the end lets you confirm the result in seconds.
At a glance
Mistake 1: single quotes instead of double quotes
The most common mistake is writing keys and text in single quotes, such as {"name": "x"} with ’ in place of “. JSON only accepts double quotes, so the parser fails at position 1, the very first character, with the message “Expected property name or ‘}’ in JSON at position 1 (line 1 column 2)”. The fix is to replace every single quote with a double quote and paste again. The same rule applies to text values: "Mumbai" is valid, ’Mumbai’ is not, and the error will point at the first single quote it meets.
Mistake 2: a comma after the last item
A trailing comma is the second most common slip. In {"a": 1,} the comma after 1 has nothing after it, so the parser fails at position 8, the closing brace, with “Expected double-quoted property name in JSON at position 8 (line 1 column 9)”. The same slip happens inside lists: {"name": "Rahul", "marks": [78, 85, 92,]} fails at the closing bracket, with “Unexpected token ‘]’”. Remove the comma before the closing brace or bracket and the text is valid. Some programming languages allow trailing commas, which is why people write them without thinking, but JSON never has.
Mistake 3: a missing value
Sometimes a key has no value at all, such as {"name": "x", "age": }, where the age is blank. The parser fails with “Unexpected token ‘}’”, because it expected a value after the colon and found the closing brace instead. This usually happens when a value was deleted while editing and the key was left behind. Either fill in the value, such as 30, or remove the key and its colon entirely, and the object becomes valid again.
Mistake 4: copying the wrong mode
People format a block in Pretty mode, copy the 9-line, 120-character version, and paste it into a place that only accepts one line, such as a single-line settings field, where the line breaks get lost or rejected. Or they copy the Compact version, 90 characters on one line, into a document where nobody can read it. The fix is to check the destination before copying: Pretty for documents and messages a person will read, Compact for fields and files a program will store. The two buttons are next to each other, and switching takes one click.
Mistake 5: pasting half the file
A long block of JSON copied from a chat message or a terminal can get cut off at the end, so the closing brace never arrives. The tool then reports an error at the end of the text, because the object was never closed. Before pasting, check that the text ends with a closing brace or bracket that matches the one it started with. A quick check is the key count: the sample must read “4 top-level keys”, and if the panel shows fewer keys than you expect, or an error at the last character, the paste was cut short.
Worked check
Check any answer against the anchor: the default sample must read 120 characters in Pretty mode and 90 characters in Compact mode, with 4 top-level keys. Paste the sample back in and confirm those three numbers. If the big line reads anything else, the input has changed, and the result on screen belongs to different text. One check, five seconds, and you know whether the output you are about to copy is the one you meant to make.
Frequently asked questions
What is the most common JSON Formatter mistake?
Single quotes instead of double quotes. JSON only accepts double quotes, so {"name": "x"} with single quotes fails at position 1.
Why does a trailing comma break my JSON?
Because JSON never allows a comma after the last item. {"a": 1,} fails at position 8, the closing brace, where a key name was expected.
What does “Unexpected token ‘}’” mean?
A value is missing, such as {"name": "x", "age": }, where the parser found the closing brace instead of a value after the colon.
How do I know my paste was cut short?
Check the key count: the sample must read 4 top-level keys. Fewer keys than expected, or an error at the last character, means the paste was cut off.
More guides on the JSON Formatter
- How to use the JSON Formatter — step by step
- JSON Formatter explained with worked examples
- JSON Formatter formula — how it actually works
- JSON Formatter for beginners — start here
- JSON Formatter vs doing it by hand — which is faster?
- JSON Formatter — The Complete Guide
- How to get an accurate result from the JSON Formatter
- JSON Formatter for students — with examples
- JSON Formatter for homeowners and DIYers
Try the JSON Formatter — free, in your browser.