C100DBA · Question #14
Which of the following are valid json documents? Select all that apply.
Option D ({ }) is the only unambiguously correct answer - an empty object is perfectly valid JSON. Option A is likely also intended as valid if the l characters are actually the number 1 (a common font rendering ambiguity); if so, {"a":1, "b":{"b":1, "c":"foo", "d":"bar"…
Question
Which of the following are valid json documents? Select all that apply.
Options
- A{"a":l, "b":{"b":l, "c":"foo", "d":"bar", "e":[l,2,4]}}
- B{"city":"New York", "population", 7999034, boros:{"queens", "manhattan", "staten island", "the
- C{"name":"Fred Flintstone";"occupation":"Miner";"wife":"Wilma"}
- D{ }
Explanation
Option D ({ }) is the only unambiguously correct answer - an empty object is perfectly valid JSON. Option A is likely also intended as valid if the l characters are actually the number 1 (a common font rendering ambiguity); if so, {"a":1, "b":{"b":1, "c":"foo", "d":"bar", "e":[1,2,4]}} is well-formed JSON with nested objects and arrays.
Option B fails for three reasons: "population" is followed by a comma instead of a colon (JSON requires key: value pairs), boros is an unquoted key (all JSON keys must be strings in double quotes), and the document is truncated - invalid JSON is never valid regardless of what comes before the cut-off.
Option C uses semicolons (;) as separators between key-value pairs; JSON strictly requires commas (,), so this is immediately disqualified.
Memory tip: Think of JSON as a very strict subset of JavaScript object syntax - keys must always be double-quoted strings, values must be one of the six valid types (string, number, boolean, null, object, array), pairs are separated by commas (never semicolons), and every opening brace/bracket needs a matching closing one. When in doubt, ask: "Would JSON.parse() accept this?"
Topics
Community Discussion
No community discussion yet for this question.