Why JSON Formatter Shows Invalid JSON

Troubleshoot invalid JSON errors caused by trailing commas, missing quotes, broken brackets, comments, encoding issues, and pasted API payload problems.

Need The Exact Result?

Use the JSON Formatter tool for the direct action. This guide stays focused on the explanation, tradeoffs, mistakes, and reference context behind that task.

Fast Answer

A JSON formatter shows an invalid JSON error when the input cannot be parsed as valid JSON. The most common causes are trailing commas, unquoted object keys, single quotes around strings, missing closing braces, comments copied from JavaScript, or invisible characters from pasted logs.

Formatting does not repair broken structure automatically. A formatter can make valid JSON readable, but it cannot safely guess which missing quote, comma, bracket, or value you intended.

The best debugging workflow is to validate first, fix the syntax error, then format the corrected payload for review or documentation.

Error Pattern Reference

Pattern What It Usually Means Fix
Unexpected token } Trailing comma or missing value before a closing brace Remove the comma or add the missing value
Unexpected token at position 0 Input may be empty, HTML, or a server error page Confirm the response starts with { or [
Unexpected string A comma may be missing between properties Add the separator between key-value pairs
Unexpected token / JavaScript-style comment was pasted into JSON Remove comments before parsing
Invalid character Smart quotes or hidden characters may be present Paste as plain text and replace invalid characters

JSON Is Stricter Than JavaScript Objects

Many invalid JSON examples come from copying JavaScript object literals and expecting them to parse as JSON. JSON requires double quotes around property names and string values. It does not allow comments or trailing commas.

A JavaScript file may tolerate patterns that JSON will reject. That distinction matters when working with API payloads, configuration files, webhook examples, and exported data from third-party systems.

If a payload came from a browser console or log view, check whether the tool copied an object representation instead of the raw JSON response.

API And Log Copy Problems

API debugging adds another layer because the copied response may not be JSON at all. An authentication failure might return an HTML login page. A proxy error might return plain text. A server exception might include logs before the JSON body.

If the first character is not { or [, inspect the source response before trying to format it. A formatter error can be a useful signal that the request failed before a real JSON response was returned.

Large payloads can also include encoded sections. If one property contains a Base64 string or escaped JSON string, decode or unescape only that property when needed. Do not alter the whole payload without understanding its structure.

Safe Debugging Workflow

  • Validate the payload before formatting it.
  • Check the first character to confirm the response is actually JSON.
  • Remove comments and trailing commas copied from JavaScript examples.
  • Replace smart quotes with normal double quotes.
  • Keep the original payload until the destination accepts the corrected version.
  • Minify only after the JSON is valid and reviewed.

Related Tools

Related Guides In This Category

Browse More Developer Guides

Need the broader support library for this topic? Visit Developer Guides for related references, comparisons, and practical background before returning to the exact tool.

Explore The Full Category

Need another related task? Open Developer Tools for the full tool set, quick-reference examples, and related category paths.