Top 30 JSON Interview Questions and Answers (2026)
Whether you're interviewing for a frontend, backend, or full-stack role, JSON questions come up in almost every technical screen. These 30 questions cover everything from basic syntax to advanced topics like streaming, schema validation, and security — with the kind of precise answers that impress interviewers.
Basics (Q1–Q8)
Q1.What is JSON and what does the acronym stand for?
Q2.What data types does JSON support?
true or false), null, object (unordered key-value pairs, keys must be strings), and array (ordered list). It does not natively support dates, undefined, or functions.Q3.What is the difference between JSON and JavaScript objects?
undefined, functions, or comments. JSON.parse() converts a JSON string into a JS object; JSON.stringify() does the reverse.Q4.Is the following valid JSON? Why or why not? <code>{`{'name': 'Alice'}`}</code>
{"name": "Alice"}.Q5.Can JSON objects have duplicate keys?
Q6.What is the maximum depth or size limit for JSON?
JSON.parse handles very large files well, but parsing a 50 MB JSON in one shot will block the main thread. Stream parsers (e.g. jsonstream in Node.js) handle arbitrarily large files.Q7.How do you handle JSON with comments?
// and /* */. (2) Strip comments before parsing with a library. (3) Add a "_comment" key as a convention. Production APIs should use standard JSON without comments.Q8.What is JSON Lines (JSONL) and when would you use it?
Parsing & Serialization (Q9–Q14)
Q9.What does JSON.parse() do when it receives invalid JSON?
SyntaxError synchronously. Always wrap JSON.parse() in a try/catch block when parsing untrusted input. The error message includes the character position of the first syntax problem, which can help you locate the issue.Q10.What is the second argument to JSON.stringify() and JSON.parse()?
JSON.stringify(value, replacer, space) — the replacer is a function or array that filters/transforms keys; space is an indent string or number for pretty-printing. JSON.parse(text, reviver) — the reviver is a function called for each key-value pair, letting you transform values (e.g., parse ISO date strings into Date objects).Q11.How do you serialize a JavaScript Date to JSON?
.toISOString() on Date objects, producing an ISO 8601 string like "2026-10-14T08:00:00.000Z". The string round-trips as a string, not a Date — use a reviver in JSON.parse to convert it back, or use a library like date-fns.Q12.What happens to undefined, functions, and Symbols in JSON.stringify()?
null. If the top-level value is undefined/function/Symbol, stringify returns undefined (not a string). This is a common source of bugs — always verify round-trip behaviour.Q13.Explain circular reference errors in JSON serialization.
JSON.stringify throws TypeError: Converting circular structure to JSON. Solutions: (1) use a replacer that tracks seen objects and skips them; (2) use a library like flatted or json-stringify-safe; (3) restructure the data to remove the cycle.Q14.How would you deep-clone a JavaScript object using JSON?
const clone = JSON.parse(JSON.stringify(obj)). It's fast and simple but lossy: drops undefined, functions, Symbols, Date objects become strings, Map/Set become {}/[]. Use structuredClone() (ES2022+) for a lossless deep clone.JSON Schema & Validation (Q15–Q19)
Q15.What is JSON Schema?
ajv (Node.js), jsonschema (Python). You can validate live in our JSON Schema Validator.Q16.What is the difference between JSON Schema draft-07 and draft-2020-12?
$dynamicRef/$dynamicAnchor for recursive schemas, prefixItems (replaces array-specific items), unevaluatedItems/unevaluatedProperties for strict validation, and $vocabulary for dialect declaration. Many production codebases still use draft-07 due to tooling support; ajv defaults to draft-2020-12 in v8+.Q17.What is additionalProperties in JSON Schema?
additionalProperties: false rejects any key not listed in properties or patternProperties. It's used to enforce strict contracts (no extra fields). additionalProperties: {type: "string"} allows extra keys but constrains their type. Omitting it (or setting true) allows anything.Q18.How do you validate that a JSON field matches a specific date format?
{"type": "string", "format": "date"} for ISO 8601 dates (YYYY-MM-DD), or "date-time" for full timestamps. Format validation is optional in the spec — validators must be told to enforce it (in ajv: {formats: require('ajv-formats')}). For custom patterns use "pattern": "^\\d4-\\d2-\\d2$".Q19.What is the oneOf / anyOf / allOf keyword?
allOf: value must satisfy all listed schemas (AND). anyOf: value must satisfy at least one (OR). oneOf: value must satisfy exactly one (XOR — useful for discriminated unions). not: value must NOT satisfy the schema. These compose schemas and are key to modelling polymorphic JSON.APIs, REST & Performance (Q20–Q25)
Q20.What Content-Type header should a REST API return for JSON?
Content-Type: application/json; charset=utf-8. Using text/json or text/plain is non-standard and may cause browsers to misinterpret the body. For JSON Patch operations use application/json-patch+json; for JSON Merge Patch use application/merge-patch+json.Q21.What is JSON Patch (RFC 6902) and when would you use it?
add, remove, replace, move, copy, test. You use it in REST APIs to send partial updates (PATCH method) without transmitting the entire resource — reducing bandwidth and enabling optimistic concurrency.Q22.How do you handle large JSON payloads in production?
?fields=id,name) to trim payload. (3) Compress with gzip/brotli — most JSON compresses 70-90%. (4) Use streaming JSON parsers on the server to avoid loading the whole document into memory. (5) Cache parsed results; avoid re-parsing on every request.Q23.What is JSONP and is it still relevant?
callback({"key":"value"}). It required script tag injection. Modern APIs use CORS headers instead, which are more secure, type-safe, and support all HTTP methods. JSONP is legacy and should not be used in new code.Q24.Explain JSON Web Tokens (JWT) structure.
header.payload.signature. The header identifies the algorithm (e.g. HS256), the payload carries claims (sub, exp, custom fields), and the signature verifies integrity. The payload is not encrypted by default — anyone can base64-decode it. Never put secrets in a JWT payload unless using JWE (JSON Web Encryption).Q25.What is the difference between JSON and BSON?
Date, ObjectId, BinData, Decimal128, Regex. BSON is faster to parse and supports larger documents (up to 16 MB) and binary data natively. The trade-off: it's not human-readable and requires a BSON library.Security (Q26–Q28)
Q26.What JSON-related security vulnerabilities should you know about?
__proto__ keys can overwrite Object.prototype. Use Object.create(null) or strip dangerous keys. 3. Billion Laughs (DoS): deeply nested or massive arrays crash naive parsers. Always set a size/depth limit. 4. Sensitive Data Exposure: logging JSON that contains passwords or tokens.Q27.What is prototype pollution and how does JSON cause it?
__proto__ or constructor.prototype via a merged JSON object, adding properties to all objects globally. Example: JSON.parse('{"__proto__": {"isAdmin": true}}') — if naively merged into another object, all objects gain isAdmin: true. Mitigations: use a safe merge library, validate schema strictly, or use Object.create(null) for parsed data.Q28.Should you use eval() to parse JSON? Why or why not?
eval('(' + jsonString + ')') executes arbitrary JavaScript, making it a critical XSS vector. Always use JSON.parse(), which is sandboxed — it only accepts valid JSON and cannot execute code. eval was a common pattern before 2009 (IE7 era); all modern engines provide fast native JSON.parse.Advanced (Q29–Q30)
Q29.How do LLMs like GPT-4 produce JSON reliably?
response_format: {type: "json_schema"} with strict: true. Anthropic uses tool-use schemas; Gemini uses response_schema. At each decoding step the sampler checks the partial output against a JSON grammar and zeros out illegal continuations. See our LLM Structured Outputs guide for practical examples.Q30.What is JSON:API and how does it differ from plain REST JSON?
data (primary resources), included (side-loaded related resources), links (pagination, self), meta, and errors. It enables compound documents (fetching a post and its comments in one request), sparse fieldsets, and relationship links. Plain REST JSON has no standard envelope — each API invents its own.Practice tip
Before your interview, load a sample JSON file into the JSON Formatter and the JSON Schema Validator so you can speak from hands-on experience.