JSON Syntax Rules β Interview Questions
β‘ 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.
βCoffee Chat Question
Concept Made Simple
βWhat are the syntax rules of valid JSON?β
π§ Mind Map Answer
Remember It Faster
β¨οΈHands-on Keyboard
Learn by Doing
// β
valid
{ "id": 1, "tags": ["a", "b"] }
// β invalid: single quotes, trailing comma, comment
{ 'id': 1, "tags": ["a", "b",], /* note */ }π₯What If?
Think Beyond the Expected
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:
β οΈ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
- 1What is JSON5 / JSONC and why do they exist?
- 2Can the top level be an array or a primitive?
- 3How do you validate JSON syntax programmatically?
π§©Related Technologies
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?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.