Unsupported data types will be converted to
null
when we want to JSON.stringify the JavaScript object
document.write(JSON.stringify({ x: 5, y: 6 }) + "<br />");
// expected output: "{"x":5,"y":6}"

document.write(JSON.stringify([new Number(3), new String('false'), new Boolean(false)]) + "<br />");
// expected output: "[3,"false",false]"

document.write(JSON.stringify({ x: [10, undefined, function(){}, Symbol('d'), new Date(2006, 0, 2, 15, 4, 5)] }) + "<br />");
// expected output: "{"x":[10,null,null,null,"2006-01-02T11:04:05.000Z"]}"
by Valeri Tandilashvili
4 years ago
JSON
JavaScript
1
Pro tip: use ```triple backticks around text``` to write in code fences