<!-- Invalid JSON? 10 Common Errors Fixed | DataSwitch Pro -->
<!-- Canonical: https://dataswitchpro.com/guides/fix-invalid-json-errors/ -->
> 

[Home](https://dataswitchpro.com/) › [Guides](https://dataswitchpro.com/guides/)

# Invalid JSON? 10 Common Syntax Errors and How to Fix Them

By the DataSwitch Pro team · November 20, 2026 · 4 min read

## Quick answer

JSON is invalid when it breaks one of its strict rules: keys and strings must use double quotes, there can be no trailing comma after the last item, no comments, and no unescaped line breaks or control characters inside strings. Paste the text into a [JSON validator](https://dataswitchpro.com/json-formatter/) to get the line and column of the first error, fix it, and validate again — later errors only appear once the first one is fixed.

JSON looks forgiving because it resembles JavaScript, but it is much stricter. A single extra comma makes the whole document unreadable to `JSON.parse`, Python's `json.loads` or any API. The good news: almost all errors come from the same short list.

## How to read the error message

Parsers report the first position where the text stops making sense, for example *Unexpected token } in JSON at position 57* or *Expecting property name enclosed in double quotes: line 4 column 3*. The real mistake is usually just **before** that position: the parser only notices the problem when it reaches the next character. A validator that shows line and column numbers makes this much faster than counting characters.

## The 10 most common errors

**1. Trailing comma.** Allowed in JavaScript, forbidden in JSON.

### Invalid → valid

```
{ "name": "Amina", "city": "Fes", }
{ "name": "Amina", "city": "Fes" }
```

**2. Single quotes.** Strings and keys need double quotes: `{'id': 1}` must be `{"id": 1}`. This often happens when a Python dictionary is printed with `print(d)` instead of `json.dumps(d)`.

**3. Unquoted keys.** `{id: 1}` is a JavaScript object literal, not JSON. Every key must be a quoted string.

**4. Comments.** `// note` and `/* ... */` are not part of JSON. Remove them, or use a format that allows comments, such as YAML, TOML or JSONC where the tool supports it.

**5. Missing comma between items.** Common when lines are pasted together: `{"a": 1} {"b": 2}` inside an array needs a comma. If the file has one object per line on purpose, it is [JSON Lines](https://dataswitchpro.com/guides/json-lines-jsonl-explained/), not JSON — convert it with [JSONL to JSON](https://dataswitchpro.com/jsonl-to-json/).

**6. Unescaped characters in strings.** A literal line break, tab or double quote inside a string is invalid. Write `\n`, `\t` and `\"` instead. Windows paths need doubled backslashes: `"C:\\data\\in.csv"`.

**7. Invalid values.** JSON has only `true`, `false` and `null` — lowercase. `True`, `None`, `undefined`, `NaN` and `Infinity` are all invalid.

**8. Number formats.** Leading zeros (`0123`), a leading plus sign, hexadecimal (`0xFF`) and a trailing dot (`5.`) are not allowed. Store codes such as `0123` as strings.

**9. Unexpected end of JSON input.** The text stops before every bracket is closed. Usually the file was truncated during download, a request failed and returned an empty body, or a log line was cut. Compare the number of opening and closing brackets, or fetch the data again.

**10. Something that is not JSON at all.** *Unexpected token < in JSON at position 0* means the response starts with `<` — it is an HTML page, often a login page or an error page from the server. Check the URL, status code and authentication instead of the JSON.

## Less obvious causes

- **A byte-order mark (BOM)** at the start of a file saved by some Windows editors. Many parsers reject it; re-save the file as “UTF-8” without BOM.
- **Smart quotes** (“ ”) copied from Word, Slack or a web page instead of straight quotes (").
- **Duplicate keys.** Technically allowed by most parsers, but only the last value survives, which silently loses data.
- **Very large numbers.** Valid JSON, but JavaScript rounds integers above 9,007,199,254,740,991. Send long IDs as strings.

## A quick workflow

1. Paste the text into the [JSON formatter and validator](https://dataswitchpro.com/json-formatter/).
2. Go to the reported line and look at the character just before it.
3. Fix that one problem and validate again until the document is valid.
4. Format (beautify) it so the structure is easy to read and the next mistake is easy to spot.

## Preventing invalid JSON

Never build JSON by joining strings. Use the language's serializer — `JSON.stringify` in JavaScript, `json.dumps` in Python, `json_encode` in PHP — which escapes quotes, line breaks and Unicode correctly every time. If people edit the file by hand, consider whether [YAML](https://dataswitchpro.com/guides/yaml-vs-json/) or TOML, which allow comments, are a better fit for that file.

**Try it on your own file.** Free, private, and processed in your browser.

[JSON Formatter](https://dataswitchpro.com/json-formatter/)[JSON to CSV](https://dataswitchpro.com/json-to-csv/)[JSON to YAML](https://dataswitchpro.com/json-to-yaml/)[JSONL to JSON](https://dataswitchpro.com/jsonl-to-json/)

## Frequently asked questions

### Does a JSON formatter fix errors automatically?

A validator shows where the error is; you decide how to fix it. Automatic repair can guess wrong, for example when a quote is missing.

### Is JSON with comments valid?

No. Standard JSON does not allow comments. Some tools accept JSONC or JSON5, but other parsers will reject those files.

### Why is the error position different from where my mistake is?

Parsers report where they noticed the problem, which is usually the character after the real mistake.

### What does “Unexpected end of JSON input” mean?

The text ended before the JSON was complete — often an empty response or a truncated file.

## More guides

- [How to Flatten Nested JSON into a CSV Table](https://dataswitchpro.com/guides/flatten-nested-json-to-csv/)
- [JSON Lines (JSONL) Explained: Format, Uses and Common Errors](https://dataswitchpro.com/guides/json-lines-jsonl-explained/)
- [How to Open and Import a JSON File in Excel (Power Query, API URL or Converter)](https://dataswitchpro.com/guides/open-json-file-in-excel/)
- [How to Convert CSV to JSON: Types, Empty Cells and Nested Keys](https://dataswitchpro.com/guides/convert-csv-to-json/)
