There is only one way to represent null
; that is with null
.
console.log(null === null); // true
console.log(null === true); // false
console.log(null === false); // false
console.log(null === 'null'); // false
console.log(null === "null"); // false
console.log(null === ""); // false
console.log(null === []); // false
console.log(null === 0); // false
That is to say; if any of the clients that consume your JSON representation use the ===
operator; it could be a problem for them.
If you want to convey that you have an object whose attribute myCount
has no value:
{ "myCount": null }
What if you to convey that you have an object with no attributes:
{}
Client code will try to access myCount
and get undefined
; it's not there.
What if you to convey that you have an object with an attribute myCount
that is an empty list:
{ "myCount": [] }