Skip to the solution
EasyPhone Screen8 min read

What is JSON and why is it commonly used?

167 views

The problem

Question presented to candidate: "What is JSON, and why do you think it became the default format for APIs and config files instead of just sending native language objects?"

What a strong answer should cover:

  • JSON (JavaScript Object Notation) is a lightweight, text-based data format for exchanging structured data, and despite the name it is language-independent -- Python, Java, Go, and every other mainstream language can read and write it.
  • JSON supports exactly six kinds of values: objects, arrays, strings, numbers, booleans, and null -- notably no functions, no undefined, no Date, no Map or Set, no BigInt.
  • JSON.stringify() serializes a JS value into a JSON string; JSON.parse() does the reverse; both accept an optional second argument (a replacer function/array, or a reviver function) for filtering or transforming values during the conversion.
  • JSON is stricter than a JavaScript object literal -- unquoted keys and trailing commas are both syntax errors to JSON.parse(), even though they would be perfectly valid inside real JS source code.
  • Real lossy edges worth naming unprompted: functions and undefined properties are dropped, Date becomes a plain ISO string (not restored as a Date on parse), Map and Set serialize to an empty object, BigInt throws, and a circular reference throws a TypeError.

Clarifying questions expected:

  • "Do you want me to also cover structuredClone as a modern alternative for deep cloning, or keep this focused on JSON itself?"

Code / implementation expected: Yes -- a short, runnable snippet demonstrating stringify/parse and the lossy edges.

  • json
  • data format
  • api
  • web

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

8 min read Β· 9 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptJSON.stringify/parse: the lossy edges, verified (run directly)

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 39 of 165 in JavaScript

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextEasy

What is the difference between == and ===?

Continue