EasyπŸ‘€ 0-2 yearsπŸ‘€ 3-5 years 1 min read

JSON Syntax Rules β€” Interview Questions

Asked inInfosysTCSCognizantAccenture
#json#syntax#valid json#rules#formatting
Report issue

⚑ 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

Keys→double-quoted strings only
Strings→double quotes (not single)
Separators→`:` key/value, `,` between items
Not allowed→trailing comma, comments, functions

⌨️Hands-on Keyboard

Learn by Doing

json
// βœ… 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:

βœ“ 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

  • 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

JSON5JSONClintersJSON.parse

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?

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.

Related Questions