Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't serialize undefined properties

See original GitHub issue

Issue Description

console.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:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

mollcommented, Feb 22, 2015

Hello again. Long time no bugfix. 😃

Anywho, this is still an issue for me as undefined values are morphed into nulls causing all kinds of weird behavior on the receiving end. Has there been any development here?

Who still thinks nulls are equivalent to undefined values that I have to convince?


drarmstrcommented, Nov 16, 2021

Any known workarounds for supporting undefined? You cannot simply create a handler for undefined (

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found