The 5 Most Common JSON Syntax Errors
1. Trailing comma: a comma after the last item in an object or array. This is valid in JavaScript and TypeScript but illegal in JSON. Wrong: {"a": 1, "b": 2,} Right: {"a": 1, "b": 2} 2. Missing comma: forgetting the comma between two properties or array elements. Wrong: {"a": 1 "b": 2} Right: {"a": 1, "b": 2} 3. Single-quoted strings: JSON requires double quotes for all strings ā both keys and values. Wrong: {'name': 'Alice'} Right: {"name": "Alice"} 4. Unquoted property names: property names must be strings in double quotes. Wrong: {name: "Alice"} Right: {"name": "Alice"} 5. Mismatched brackets: an unclosed { or [ anywhere in the document causes a parse error at end of file. Most formatters report this as 'unexpected end of JSON input' or 'Unexpected token' at the last character.
How to Read JSON Error Messages
Browser console: 'SyntaxError: Unexpected token , in JSON at position 47' ā this means position 47 (zero-indexed character offset from the start of the string) has an unexpected comma. Count characters from the start or paste into a formatter that converts position to line+column. Node.js: 'SyntaxError: Unexpected token } in JSON at position 120' ā the } at position 120 was not expected. Usually means there is a trailing comma before it or a missing opening brace. Python json.decode: 'json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 3 column 5' ā directly names the line and column, much easier to locate. The key insight: the error position is where the parser noticed the problem, not always where you made the mistake. A missing closing bracket at line 5 may only surface as an error at line 50 when the parser hits end-of-input. Work backwards from the error location when the obvious fix is not at that position.
Step-by-Step: Fixing JSON with a Formatter
Step 1: Paste your JSON into the ToolMint JSON Formatter input panel. Step 2: The validator runs automatically. If there is an error, the error badge shows the line number and column. Step 3: Navigate to that location in your source and look for: ⢠A trailing comma on the previous line ⢠Single quotes instead of double quotes ⢠A missing comma between properties ⢠An unquoted property name Step 4: Fix the issue in your source, re-paste the corrected JSON, and verify the validator shows 'Valid JSON'. Step 5: Use the Format (beautify) button to see the full structure with proper indentation ā mismatched nesting becomes visually obvious in a formatted view.
How to Avoid JSON Errors in Code
Never hand-write JSON for production use. Instead: ⢠In JavaScript/Node: use JSON.stringify(object) to serialize data ā it always produces valid JSON ⢠In Python: use json.dumps(dict) ā produces valid JSON ⢠In other languages: use the built-in JSON serializer for that language When you must write JSON manually (config files, test fixtures, seed data), use a JSON-aware editor (VS Code highlights syntax errors inline) or run the file through a validator before committing. For config files where trailing commas and comments are convenient, use JSONC (JSON with Comments) format supported by VS Code, or use YAML instead ā YAML is a superset of JSON that allows comments and is more forgiving of minor formatting differences.