JSON Syntax Rules Explained (With Examples)

By Ramanathan Aug 9, 2026 2 min read JSON Formatter & Validator

JSON is strict in a few specific ways, and almost every "invalid JSON" error comes from breaking one of these rules. Here they are, each with a valid and an invalid example so the difference is obvious.

Keys must be double-quoted strings

Every key is a string in double quotes — no exceptions, even for simple names.

{ "name": "Ada" }
{ name: "Ada" }

The second is a JavaScript object literal, not JSON. This is the single most common mistake when people paste code into a JSON tool.

Strings use double quotes, never single

{ "role": "engineer" }
{ "role": 'engineer' }

Single quotes are valid in JavaScript and Python but never in JSON.

No trailing commas

The last item in an object or array cannot be followed by a comma.

{ "a": 1, "b": 2 }
{ "a": 1, "b": 2, }

Trailing commas are allowed in modern JavaScript, which is exactly why they sneak into JSON by accident.

Only six value types

A JSON value is one of: string, number, boolean (true/false), null, object ({ }), or array ([ ]). That's it.

{ "count": 3, "active": true, "note": null, "tags": ["a", "b"] }
{ "count": NaN, "created": undefined, "fn": function(){} }

NaN, Infinity, undefined, functions, and dates are all invalid. A date is written as a string, usually ISO 8601: "2026-08-09T12:00:00Z".

No comments

{ "port": 8080 }
{
  // the server port
  "port": 8080
}

Plain JSON has no // or /* */. Formats that allow them (like JSONC) are supersets of JSON, not JSON itself.

Numbers are plain

Numbers are written without quotes, leading zeros, or a trailing decimal point: 42, -3.14, 2.5e8 are valid; 042, .5, and 5. are not.

Whitespace doesn't matter

Spaces, tabs, and newlines between tokens are ignored, so indentation is purely for humans. That's why running a formatter on valid JSON is always safe — it changes how the data looks, never what it means.

The bigger picture

These rules sit inside the larger JSON story — types, structure, and format comparisons — covered in The Complete Guide to JSON. Breaking one of them usually produces a parse error; see Common JSON Errors and How to Fix Them.

Try it

Paste your JSON to check it against every rule above — invalid input is flagged with the exact line and column, right in your browser.

About the author

Ramanathan · Software Engineer & Solutions Architect

I'm a Software Engineer and Solutions Architect with 20+ years of experience building enterprise applications across BFSI, Healthcare, Retail, Manufacturing, and Industrial Automation. I've spent those two decades living in JSON, tokens, regexes, and config files — so I built the fast, private, no-login developer tools I always wanted to reach for myself.

Last updated: Aug 9, 2026