FreeToolGrid

Developer workflows

How to Fix Common JSON Formatting Errors

Open JSON Formatter

JSON is a strict data format, not a JavaScript object literal. An object that looks reasonable in source code can still be invalid JSON because of single quotes, comments, or a comma after the last item. Formatting makes valid JSON easier to read, but a parser cannot safely guess how broken data was meant to look.

Start by identifying the first syntax error, correcting it, and parsing again. One missing quote near the beginning can make a later line look wrong. The examples below use a small configuration object so each change is easy to check.

JSON Formatter input controls on FreeToolGrid
JSON Formatter

Compare against a small valid document

JSON object keys and string values need double quotes. Numbers, true, false, and null are not quoted. Objects use braces, arrays use brackets, and a colon separates each property name from its value. Commas separate properties or array elements, but there is no comma after the last one.

Paste this sample into the JSON Formatter and format it. Whitespace around tokens is not significant, so compact and indented versions represent the same basic structure. Whitespace inside a quoted string is data and should not be removed casually.

{
  "name": "Weekly report",
  "enabled": true,
  "retries": 3,
  "tags": ["finance", "draft"],
  "owner": null
}

Fix the syntax, not just the indentation

Replace single-quoted keys or values with properly escaped double-quoted strings. Remove comments and trailing commas if the file really is intended to be JSON. Check that each opening brace or bracket has the correct closing character. A missing comma between properties is different from an extra comma after the last property.

Strings cannot contain an unescaped literal line break. Use the escape sequence backslash-n for a newline inside a string. Backslashes themselves need escaping, which often matters for Windows file paths. Do not repair a document with a global quote replacement: apostrophes inside legitimate text are not syntax errors.

  1. Read the first parser error and inspect the nearby token.
  2. Check quotes, commas, colons, and matching brackets.
  3. Parse again after one small correction.
  4. Compare important values with the original source before using the result.

Valid JSON can still contain wrong data

Syntax validation does not check whether a field is allowed, required, or meaningful. A valid document with a negative retry count may still fail your application's schema. Use a schema validator or the application's own validation when you need to enforce those rules.

JavaScript numbers cannot exactly represent every large integer. IDs larger than the safe integer range should usually be strings when their exact digits matter. Duplicate object keys are also risky because common parsers retain only one value. A parse-and-format operation can therefore change the interpretation of unusual input even when the output is valid JSON.

Keep a copy and protect sensitive values

Work on a copy of configuration or API data, especially when debugging production issues. Remove secrets before sharing examples with another person. FreeToolGrid's formatter runs in the browser, but that does not make the surrounding device, browser extensions, or clipboard automatically secure.

After formatting, review the values, run the consuming application's tests, and save the result in the format that application expects. A file that accepts comments or trailing commas may be JSON5 or another configuration language, not strict JSON. Do not strip features without first identifying the intended parser.

Common errors and corrections

Common errors and corrections
Invalid JSONValid JSONReason
{'count': 3}{"count": 3}Keys need double quotes
{"count": 3,}{"count": 3}No trailing comma
{"ready": True}{"ready": true}Boolean literals are lowercase

Common questions

Does JSON have to start with an object?

No. A JSON document can contain an array, string, number, boolean, or null as its top-level value. A particular application may impose a stricter requirement.

Does a formatter validate my API contract?

No. Parsing checks JSON syntax. It does not establish that the fields, types, permissions, or business rules match your API.

Further reading

Business

Money

Everyday math

Images & files

Writing

Browse all guides