JavaScript JSON Handling (stringify, parse pitfalls) Quiz
Answer 40 questions covering JSON.stringify basics, JSON.parse behavior, handling undefined and functions, circular structure errors, Date serialization, number precision, reviver/replacer usage, and safe parsing practices.
Question 1
What does JSON.stringify primarily do?
Question 2
Why does JSON.stringify ignore non-enumerable properties?
Question 3
What prints?
const user = { name: 'Ayu', age: 29 }
console.log(JSON.stringify(user))Question 4
What is the second parameter of JSON.stringify used for?
Question 5
What does JSON.parse do?
Question 6
Which JSON string is invalid for JSON.parse?
Question 7
What prints?
const data = '{"price": 7.5, "active": true}'
const parsed = JSON.parse(data)
console.log(parsed.price + parsed.active)Question 8
How does the reviver parameter in JSON.parse work?
Question 9
How does JSON.stringify treat undefined in objects?
Question 10
What happens to functions during JSON.stringify?
Question 11
What prints?
const item = { id: 1, onClick() {} }
console.log(JSON.stringify(item))Question 12
How does JSON.stringify treat undefined in arrays?
Question 13
Why does JSON.stringify throw when encountering a circular reference?
Question 14
What prints?
const obj = { name: 'loop' }
obj.self = obj
try {
JSON.stringify(obj)
} catch (err) {
console.log(err.name)
}Question 15
How can you serialize objects with cycles safely?
Question 16
How are Date objects serialized by JSON.stringify?
Question 17
What prints?
const data = { createdAt: new Date('2025-01-01T10:00:00Z') }
const text = JSON.stringify(data)
console.log(text)
const parsed = JSON.parse(text)
console.log(parsed.createdAt instanceof Date)Question 18
How can reviver help with Date restoration?
Question 19
Why can JSON.stringify lose precision for very large integers?
Question 20
What prints?
const big = { value: 9007199254740993 }
const text = JSON.stringify(big)
console.log(text)
const parsed = JSON.parse(text)
console.log(parsed.value === big.value)Question 21
How can you preserve arbitrary-precision integers through JSON?
Question 22
What can a replacer array do in JSON.stringify?
Question 23
What prints?
const payload = { id: 1, secret: 'abc', nested: { secret: 'xyz', id: 2 } }
const replacer = (key, value) => (key === 'secret' ? undefined : value)
console.log(JSON.stringify(payload, replacer))Question 24
What does a reviver return to delete a key during parsing?
Question 25
How can reviver help convert strings to numbers safely?
Question 26
Why should JSON.parse be wrapped in try/catch when dealing with external data?
Question 27
What prints?
const bad = "{\"id\":1,,}"
try {
JSON.parse(bad)
} catch (error) {
console.log(error instanceof SyntaxError)
}Question 28
Which practice helps avoid prototype pollution when parsing JSON?
Question 29
Why is eval an unsafe alternative to JSON.parse?
Question 30
How does JSON.stringify handle Symbol-valued properties?
Question 31
What prints?
const weird = { key: Symbol('token') }
console.log(JSON.stringify(weird))Question 32
Why can JSON.parse cause performance issues on massive payloads?
Question 33
How can streaming parsers mitigate large JSON issues?
Question 34
What prints?
const json = '{"value": NaN }'
try {
JSON.parse(json)
} catch (error) {
console.log(error.message)
}Question 35
Why does JSON not support Infinity or NaN?
Question 36
How can you safely stringify user-generated content containing control characters?
Question 37
What prints?
const input = "{\"__proto__\":{\"polluted\":true}}"
const parsed = JSON.parse(input)
console.log(parsed.polluted, Object.prototype.polluted)Question 38
Why is manual schema validation important after parsing trusted but complex JSON?
Question 39
What prints?
const text = JSON.stringify({ emoji: "😀" })
console.log(text.length)
const parsed = JSON.parse(text)
console.log(parsed.emoji)Question 40
Which best practice helps when logging JSON.stringify output for debugging?
