Reputation: 1069
I'm building an application that parses a JSON template and then replaces the values of the objects with new data. My question is what is the standard way to represent empty data in JSON?
This is how I'm handling this right now:
""
null
Is this correct?
Upvotes: 6
Views: 33244
Reputation: 3317
It should be pretty straight forward.
{
"Value1": null,
"Value2": null,
}
Null represents a null-able datatype so your business layer needs then to know if that is an int, double, string ...
Upvotes: 7
Reputation: 21272
It is entirely up to you.
The falsy values in JavaScript are:
false
null
undefined
0
NaN
''
or ""
You can use any of these to represent an empty value. However, keep in mind that when you try to access an object's property which doesn't exist, you will get undefined
. So undefined
can be considered the standard null value, in a way.
Having said that, one convention is to use null
so that you can distinguish a property that has been intentionally set to null
from a property that is actually undefined
.
Upvotes: 0