Don't serialize undefined properties
See original GitHub issueconsole.log(Transit.writer("json").write({name: undefined}))
The above currently returns ["^ ","name",null]
.
I would argue null
and undefined
are different concepts. Both are falsy in the JavaScript sense, sure, but not equivalent in the semantic sense. Null could be said to be a known “unset” value (like in a tuple of false
, true
, null
). Undefined, however, could be said to mean an unknown value entirely.
As Dave Herman said in July 29 2014 TC39 Meeting Notes:
- `null` represents the no-object object, just like NaN represents the no-number number
- `undefined` represents the no-value value
I propose to either ignore undefined
properties in objects entirely or add an explicit tag for it. But few languages have both a null
and undefined
, and that would require changing the Transit protocol. Better just ignore them like JSON.stringify
does.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Creating json objects to exclude undefined properties
and don't worry with undefined values, because JSON.stringify doesn't serialize keys with undefined values.
Read more >JSON.stringify removes undefined, how to keep it
JSON.stringify will omit all object attributes that are undefined . In most cases, it doesn't really matter, because if we parse that ...
Read more >Serializing - MikroORM
The opposite situation where you want to define a property that lives only in memory (is not persisted into database) can be solved...
Read more >Handling JSON null and empty arrays and objects - IBM
When serializing to JSON, if a value of a property in the data object is null, then it will be serialized as a...
Read more >SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
Examples · JSON.parse() does not allow trailing commas · Property names must be double-quoted strings · Leading zeros and decimal points.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello again. Long time no bugfix. 😃
Anywho, this is still an issue for me as
undefined
values are morphed intonull
s causing all kinds of weird behavior on the receiving end. Has there been any development here?Who still thinks
null
s are equivalent toundefined
values that I have to convince?Cheers
Any known workarounds for supporting
undefined
? You cannot simply create a handler forundefined
(https://github.com/cognitect/transit-js/blob/master/src/com/cognitect/transit/impl/writer.js#L65)