JSON Syntax Rules — Interview Questions
Reviewed by Gurusankar M.
Short Answer
Valid JSON: data is name/value pairs; objects use {}, arrays use []; keys and string values must use double quotes; values are string/number/boolean/null/object/array; items are comma-separated with NO trailing comma; no comments; the whole document is one value. Whitespace between tokens is ignored.
On this page
Concept Made Simple
Coffee Chat Question
“What are the syntax rules of valid JSON?”
Remember It Faster
Mind Map Answer
- Keys
- double-quoted strings only
- Strings
- double quotes (not single)
- Separators
- `:` key/value, `,` between items
- Not allowed
- trailing comma, comments, functions
Learn by Doing
Hands-on Keyboard
// ✅ valid
{ "id": 1, "tags": ["a", "b"] }
// ❌ invalid: single quotes, trailing comma, comment
{ 'id': 1, "tags": ["a", "b",], /* note */ }Think Beyond the Expected
What If?
Why does a trailing comma break JSON when JavaScript allows it?
JSON is a strict subset of JavaScript's object syntax and the spec forbids trailing commas, comments, and single quotes to keep parsers simple and unambiguous. JS object literals are more forgiving, but JSON.parse follows the strict grammar — a trailing comma throws a SyntaxError.
Real World
The classic 3am bug: someone hand-edits a config file, leaves a trailing comma or a comment, and the whole service fails to boot. Linters and JSON5/JSONC exist precisely because strict JSON is unforgiving of these.
Interviewer's Expectation
Keywords they're listening for:
- objects {} / arrays []
- double-quoted keys & strings
- comma-separated, no trailing comma
- no comments
- one root value
Common Mistakes
- Trailing comma after the last item
- Single quotes or unquoted keys
- Adding // or /* */ comments
Best Practices
- Lint/validate JSON in CI and editors
- Use JSONC/JSON5 only where the parser supports it
- Never hand-edit critical JSON without validation
Follow-up Questions
- What is JSON5 / JSONC and why do they exist?
- Can the top level be an array or a primitive?
- How do you validate JSON syntax programmatically?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Syntax (JSON) Interview question: "What are the syntax rules of valid JSON?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair